以下是引用gwcome在2013-3-17 15:02:54的发言:
//自己写着玩的,是关于友元函数
#include<iostream>
class Lovers
{
public:
void kiss_action();
protected:
void kiss();
private:
};
class Girlfriend :public Lovers
{
friend class Others;
public:
void kiss_action();
protected:
void kiss();
private:
};
class Boyfriend :public Lovers
{
public:
void kiss_action();
protected:
void kiss();
private:
};
class Others
{
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();//“Girlfriend::kiss_action”: 非静态成员函数的非法调用
std::cout<<"I am a third..hehe";
}
int main()
{
Lovers lovers;//定义对象 ...TAT...
lovers.kiss_action();
Girlfriend girlfriend;
girlfriend.kiss_action();
Boyfriend boyfriend;
boyfriend.kiss_action();
Others others;
others.kiss_other();
return 0;
}
我定义了对象 还是有错
//自己写着玩的,是关于友元函数
#include<iostream>
class Lovers
{
public:
void kiss_action();
protected:
void kiss();
private:
};
class Girlfriend :public Lovers
{
friend class Others;
public:
void kiss_action();
protected:
void kiss();
private:
};
class Boyfriend :public Lovers
{
public:
void kiss_action();
protected:
void kiss();
private:
};
class Others
{
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();//“Girlfriend::kiss_action”: 非静态成员函数的非法调用
std::cout<<"I am a third..hehe";
}
int main()
{
Lovers lovers;//定义对象 ...TAT...
lovers.kiss_action();
Girlfriend girlfriend;
girlfriend.kiss_action();
Boyfriend boyfriend;
boyfriend.kiss_action();
Others others;
others.kiss_other();
return 0;
}
我定义了对象 还是有错
程序代码:
#include "stdafx.h" //自己写着玩的,是关于友元函数 #include<iostream> class Lovers { public: void kiss_action(); protected: void kiss(); private: }; class Girlfriend :public Lovers { friend class Others; public: void kiss_action(); protected: void kiss(); private: }; class Boyfriend :public Lovers { public: void kiss_action(); protected: void kiss(); private: }; class Others { 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 girl; girl.kiss(); std::cout<<"I am a third..hehe"; } int main() { Lovers lovers;//定义对象 ...TAT... lovers.kiss_action(); Girlfriend girlfriend; girlfriend.kiss_action(); Boyfriend boyfriend; boyfriend.kiss_action(); Others others; others.kiss_other(); return 0; }
我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...