Bad voodoo or common practice?
Is it acceptable practice to access one classes private members from another instance of that class? Or should it be accessed through the Get() method provided?
Example:
doit::operator+=( doit& add )
{
x+=doit.x; // x is private member of doit...
}
Thanks,
Jumpster
Regards,JumpsterSemper Fi
Oooppss...
That should read x+=add.x; // x is private member of doit...
Sorry.
That should read x+=add.x; // x is private member of doit...
Sorry.
Regards,JumpsterSemper Fi
Its common practice.
Because if you are creating a function for a class you have no access restrictions.
Because if you are creating a function for a class you have no access restrictions.
Uugghh!!
I tried to inherit from the class with an overloaded method (operator +=) and the inherited class gave compiler errors regarding the initial private member. Had to make it protected to work properly. Who knew? Ok, besides me?
So it is otherwise, common practice? Just checking.
Thanks,
Jumpster
I tried to inherit from the class with an overloaded method (operator +=) and the inherited class gave compiler errors regarding the initial private member. Had to make it protected to work properly. Who knew? Ok, besides me?
So it is otherwise, common practice? Just checking.
Thanks,
Jumpster
Regards,JumpsterSemper Fi
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement