D
Dan Smithers
Can a make a private member function a friend? The code below suggests
not. I am using g++ 4.2.3
I realise that I can make the whole CFriend class a friend, or make my
friend function public but I don't really want to do either.
thanks
dan
#include <iostream>
class CClass;
class CFriend
{
private:
CClass& my_target;
void myWork(void);
public:
CFriend(CClass& target):my_target(target){;}
virtual ~CFriend(void){;}
void work(void){return myWork();}
};
class CClass
{
private:
void doWork(void)
{
std::cout << " CClass doWork() my_val = " << my_val++ << std::endl;
}
int my_val;
public:
CClass(int val):my_val(val){;}
virtual ~CClass(void){;}
friend void CFriend::myWork(void);
};
void
CFriend::myWork(void)
{
my_target.doWork();
}
int
main(int argc, char *argv[])
{
CClass first(1);
CFriend second(first);
second.work();
}
not. I am using g++ 4.2.3
I realise that I can make the whole CFriend class a friend, or make my
friend function public but I don't really want to do either.
thanks
dan
#include <iostream>
class CClass;
class CFriend
{
private:
CClass& my_target;
void myWork(void);
public:
CFriend(CClass& target):my_target(target){;}
virtual ~CFriend(void){;}
void work(void){return myWork();}
};
class CClass
{
private:
void doWork(void)
{
std::cout << " CClass doWork() my_val = " << my_val++ << std::endl;
}
int my_val;
public:
CClass(int val):my_val(val){;}
virtual ~CClass(void){;}
friend void CFriend::myWork(void);
};
void
CFriend::myWork(void)
{
my_target.doWork();
}
int
main(int argc, char *argv[])
{
CClass first(1);
CFriend second(first);
second.work();
}