Say if we ve certain private methods along with private data members and public methods. other than friend function is thr any other way we access these members(they being private only) directly. its one of the requirements in a project of mine.
The only other safe way is a member function of a friend class. I can think of three unsafe ways to do it, but they're all hit or miss and they all break something serious. I think you might be misunderstanding the requirement for your project.though one of the cheap n unprofesssional sol is
#define private public but this unwantedly unveals many non required methods toopen arena
It's also not allowed. The language standard doesn't let you redefine keywords. It's also not sure to work if the private section isn't explicit. For example.
class x
{
void meth1()
{
cout<<"Meth1";
}
void meth2()
{
cout<<"meth 2";
}
}; The default access level of a class is private, but your trick won't work with the above class because it doesn't use the private keyword explicitly. It also won't work if you don't have access to the source code because by the time a class is compiled to object code, the keywords are long gone and the preprocessor from client code won't be able to touch it.
The simple answer is that you can't do what you're asking. The complicated answer is that you can do anything if you have sufficient knowledge of how the internals of the compiler work, but it's not portable and it's more likely to seriously screw something up than do any good. ;)