The function Reg::clone() is not a static function, it is a member function. You need to instantiate an object of type Reg and then use that member function. Alternatively and if Reg is a class of your own making you can declare it as static and that's it.
+1 firedraco's approach, but with a twist. For me, clone() is a good candidate to be static too.
1 2 3 4 5 6 7 8 9
staticvoid SocReg::clone(SocReg &dest, const SocReg &src);
//And the member function uses the static version so we don't repeat code.
SocReg SocReg::clone(void) const
{
SocReg newObj;
SocReg::clone(newObj, *this);
return newObj;
}
But now that I write that I see it is inefficient. I call for C++ experts here, as I am not a very expert one. I think clone should use the copy constructor so I can return SocReg(*this);. Suggestions?
I'm limited in my implementation choices here. I've overridden the assignment operator so that:
reg1 = reg2;
results in:
reg1.n = reg2.c;
What I want to do in my copy constructor is a full copy (a clone, if you will). I can't use the assignment operator, so I don't think I can use your suggestion, unless I'm misunderstanding something.
You are creating a copy constructor for a class named Cell. This class, as far as I can tell, has a member variable of type SocReg, which is another class of yours. Whenever the copy constructor of Cell is called you also want a copy of this other member variable. Right?
I am saying this: Instead of providing a clone() function in the SocReg class, provide a copy constructor. If you have no need to override the default copy constructor, then great!
Actually, if you provide an appropriate copy constructor for the class SocReg, and if Cell's copy constructor's sole purpose is to call clone(), then you can forego the copy constructor of Cell because the compiler-provided copy constructor will just use SocReg's copy constructor and everything will be just fine.