/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#include <string>
class Pair
{
std::string name;
public:
int a;
int b;
Pair(const char *_name, int _a = 0, int _b = 0)
: name(_name)
, a(_a)
, b(_b)
{
printf("Pair %s (%p) created.\n", _name, this );
}
// Destructooooor!!
~Pair()
{
a = 0;
b = 0;
printf( "Pair %s (%p) destroyed\n", name.c_str(), this );
}
// Makes a copy of the variables, but not the name.
Pair &operator =(const Pair &other)
{
a = other.a;
b = other.b;
printf( "Pair %s (%p) copied from %s (%p) \n", name.c_str(), this, other.name.c_str(), &other );
return *this;
}
};
Pair manGiveMeAPairCopy(const Pair &p)
{
Pair tmp("Local pair");
tmp = p;
return tmp;
}
int main()
{
Pair pair1("Pair 1", 10, 20);
Pair pair2("Pair 2");
pair2 = manGiveMeAPairCopy(pair1);
return 0;
}