overloaded operator=

Omni

Ultra Cool Member
Reaction score
37
I have made myself some class (c++), wich is going to be a sort of garbage collector.
and i've overloaded the = operator to make things work right

the class is named PtrCon
Code:
PtrCon& operator=(const PtrCon<t> &d)
{
	//.....
	return *this;
}


when i do
Code:
PtrCon<int> pcA;
PtrCon<int> pcB;
pcB = pcA;
everything works fine, the pcB.operator= is called

but when i do
Code:
PtrCon<int> pcA;
PtrCon<int> pcB = pcA;
it doesnt call pcB.operator=

anyone know why this is?
 

0_Flip

New Member
Reaction score
2
the operator= function will not be called with
Code:
PtrCon<int> pcA;
PtrCon<int> pcB = pcA;

because you are initializing pcB,'
wich calls the constructor

for example
Code:
PtrCon<int> pcB(pcA);
is exactly the same,

so what you'll have to do is make a constructor for your
class that accepts a PtrCon reference, example:
Code:
PtrCon(const PtrCon<t> &d)
{
    operator=(d);
}

and it will work like you want it to
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top