Advertisement

Bad voodoo or common practice?

Started by September 12, 2000 01:18 PM
2 comments, last by Jumpster 24 years, 3 months ago
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.
Regards,JumpsterSemper Fi
Advertisement
Its common practice.

Because if you are creating a function for a class you have no access restrictions.
-------homepage - email
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
Regards,JumpsterSemper Fi

This topic is closed to new replies.

Advertisement