|
From: Alfred P. R. <al...@ya...> - 2005-05-16 16:04:16
|
Possibly declare main as a friend in the private section of MyClass instead? Also, I'd get away from calling a friend member function main or Main, due to what the linker may try to do with that label.
Farzan Hajian <far...@ho...> wrote:Dear C++ users,
I have problem with friend functions and namespaces.
Assume we have class "MyClass" defined in namespace "MyNameSpace":
namespace MyNameSpace
{
class MyClass
{
private:
int data;
public:
int func(){}
friend int main();
};
}
using namespace name;
int main()
{
C obj;
obj.data;
return 0;
}
I want to allow "main()" to access private members so I made it friend
for the class. Since "main()" does not belong to "MyNameSpace" the
compiler can not make it a friend for the class. It trys to find a
"main()" function which belongs to the namespace not a "Main()" function
outside.
Now I want to k now if there is solution for this problem.
Thanks,
<snip>
Alfred P. Reaud
|