Heh, the reason Narue and Salem were so abrubt with their responses is because the OP's question is basically asking "how to I break the rules for OOP without getting in trouble?" The answer that will usually work is to have get/set methods. Sometimes that isn't quite what you want, and you use a friend, but the OP specified that friends weren't allowed.
>> Indeed breaking the rules of OO is a horrible thing. But that doesn't mean that there are cases in real life when you are forced to do that.
This requires you to know how the compiler will lay the data out in memory, plus a bit of ugly hacking. Not a good solution.
>> True That's why I wrote "If you know the object layout..."
Horrible idea. There's a reason for having private members, making them public is a very bad idea.
>> NONE of these solutions should be implemented given a choice. They are all horrible. One should do proper OO design, encapsulation, get/set methods, insulation as/if/when you need, BUT IF YOU HAVE A CHOICE.
by the way, Narue is very much an expert, and highly respected on the forum. She just has a sharp wit :p
>> As can be seen I'm a newbi poster. Sorry to Narue. Just that she could have as well given the answer/link-to-answer and said "don't do this at home".
---------------------------------
Gee, ya think there might be something fundamentally WRONG with your design if you have to resort to this kind of crap?
>> Of course there is something fundamentally WRONG with your design ! There is no question abt it, but WHAT IF you can't change the design and need a "quick fix" to satisfy the customer and honor your SLA?? That's the whole point.
In other words, completely forget about pretending to program in C++, and use something called 'Super C'
>> Again I never said ANY of these solutions should be implemented given a choice. Do proper OO design, encapsulation, get/set method, insulation if you need, IF YOU HAVE A CHOICE.
And poking away at the innards of some class doesn't need testing - boggle!!!!
>> Of course it needs, but only in the user component not ALL. That means less time, faster patch.
I'm glad you're nowhere near any code I'm responsible for.
>> Given the amount you brag I would be very interested in seeing this "any code I'm responsible for".
What are you going to do after the change?
Implement it properly with a proper access method?
>> OF COURSE YES ! Is there a question abt it? Who in their right frame of mind would like to have some crap code like this in their customer realse for long ?!
>> Finally how abt you at least give few solutions to the problem?
---------------------------------
Guys, you got the attitude from me simply coz you gave some. If it was out of place, please do forgive me.
But you are the experts so be like them. There is a say in my language (Gujarati) "When mongos grow on a mango tree, the tree bows down (NOT UP)."