online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> template <class T> class comprehendTemplate { private: T* val; public: comprehendTemplate(T* num):val(new T) { std::cout << "Parameterised Constructor" << std::endl; val = num; std::cout << "val " << *val << std::endl; } comprehendTemplate(const comprehendTemplate& other) { std::cout << "Copy Constructor" << std::endl; val = other.val; } comprehendTemplate& operator=(const comprehendTemplate& other) { if (this != &other) { std::cout << "Assignment Operator Constructor" << std::endl; val = other.val; } return *this; } T* getVal(){ return val; } }; int main() { int var = 9; comprehendTemplate <int>ct(&var); //comprehendTemplate <std::string>ct2("Hello"); std::cout << "getVal of ct " << ct.getVal() << " " << *(ct.getVal()) << std::endl; //std::cout << "getVal of ct2 " << ct2.getVal() << std::endl; comprehendTemplate <int>ct3 = ct; std::cout << "ct3 is a copy of ct " << ct3.getVal() << std::endl; //var = 10; int var2 = 10; comprehendTemplate <int>ct4(&var2); std::cout << "getVal of ct4 " << ct4.getVal() << " " << *(ct4.getVal()) << std::endl; ct4 = ct; std::cout << "ct4 replaces the data with ct " << ct4.getVal() << std::endl; return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue