![]() |
#2
peach54602013-03-17 11:48
|

//自己写着玩的,是关于友元函数
#include<iostream>
class Lovers
{
friend class Others;
public:
void kiss_action();
protected:
void kiss();
private:
};
class Girlfriend :public Lovers
{
public:
void kiss_action();
protected:
void kiss();
private:
};
class Boyfriend :public Lovers
{
public:
void kiss_action();
protected:
void kiss();
private:
};
class Others
{
//friend class Girlfriend;
//friend class Lovers;
public:
void kiss_other();
protected:
private:
};
void Lovers::kiss()
{
std::cout<<"I want kiss";
}
void Lovers::kiss_action()
{
Lovers::kiss();
}
void Girlfriend::kiss()
{
Lovers::kiss_action();
std::cout<<"my girlfriend I am a normal boy";
}
void Girlfriend::kiss_action()
{
Girlfriend::kiss();
}
void Boyfriend::kiss()
{
Lovers::kiss_action();
std::cout<<"my boyfriend I am a gayboy";
}
void Boyfriend::kiss_action()
{
Boyfriend::kiss();
}
void Others::kiss_other()
{
Girlfriend::kiss_action();//“Girlfriend::kiss_action”: 非静态成员函数的非法调用
std::cout<<"I am a third..hehe";
}
int main()
{
Lovers::kiss_action();//“Lovers::kiss_action”: 非静态成员函数的非法调用
Girlfriend::kiss_action();//“Girlfriend::kiss_action”: 非静态成员函数的非法调用
Boyfriend::kiss_action();//“Boyfriend::kiss_action”: 非静态成员函数的非法调用
Others::kiss_other();
return 0;
}
#include<iostream>
class Lovers
{
friend class Others;
public:
void kiss_action();
protected:
void kiss();
private:
};
class Girlfriend :public Lovers
{
public:
void kiss_action();
protected:
void kiss();
private:
};
class Boyfriend :public Lovers
{
public:
void kiss_action();
protected:
void kiss();
private:
};
class Others
{
//friend class Girlfriend;
//friend class Lovers;
public:
void kiss_other();
protected:
private:
};
void Lovers::kiss()
{
std::cout<<"I want kiss";
}
void Lovers::kiss_action()
{
Lovers::kiss();
}
void Girlfriend::kiss()
{
Lovers::kiss_action();
std::cout<<"my girlfriend I am a normal boy";
}
void Girlfriend::kiss_action()
{
Girlfriend::kiss();
}
void Boyfriend::kiss()
{
Lovers::kiss_action();
std::cout<<"my boyfriend I am a gayboy";
}
void Boyfriend::kiss_action()
{
Boyfriend::kiss();
}
void Others::kiss_other()
{
Girlfriend::kiss_action();//“Girlfriend::kiss_action”: 非静态成员函数的非法调用
std::cout<<"I am a third..hehe";
}
int main()
{
Lovers::kiss_action();//“Lovers::kiss_action”: 非静态成员函数的非法调用
Girlfriend::kiss_action();//“Girlfriend::kiss_action”: 非静态成员函数的非法调用
Boyfriend::kiss_action();//“Boyfriend::kiss_action”: 非静态成员函数的非法调用
Others::kiss_other();
return 0;
}