| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
#include <iostream> 
#include <cstdio> 
using namespace std; 
 
class Lover 
{ 
protected: 
    { 
        string name; 
        Lover(string thename) 
        { 
            name=thename; 
        } 
        friend class Other; 
    } 
public: 
        void kiss(string name1,string name2) 
        { 
            cout<<name1<<' '<<"kiss"<<' '<<name2<<endl; 
        } 
        void ask(string name1,string name2) 
        { 
            cout<<name1<<"ask"<<name2<<"to do sth"<<endl; 
        } 
     
}lover; 
 
 
class Boyfriend:public Lover 
{ 
protected: 
    { 
        Boyfriend(string thename ):Lover(thename); 
}; 
 
class Girlfriend:public Lover 
{ 
protected: 
    { 
        Girlfriend(string thename):Lover(thename); 
    } 
}; 
 
class Other 
{ 
protected: 
    { 
        string name; 
        Other(string thename) 
        { 
            name=thename; 
        } 
    } 
}; 
 
int main() 
{ 
    Other other(other); 
    Girlfriend girlfriend(girlfriend); 
    Boyfriend boyfriend(boyfriend); 
    lover.kiss(other.name,girlfriend.name); 
    return 0; 
} 
看小甲鱼视频学的c++,看到21p那里,就自己按小甲鱼要求写了个程序,结果老是报错,看了几小时了。这程序快把我这个新手搞死了。大佬们帮我这个新手看看,感激不尽!
1.)C++ 用头文件 include <iostream> 就不要多此一举 include <cstdio> 
2.)请检查你的类构造(为什么有那么多花括号?),正确构造:- class xxxx
 
 - {
 
 -     public:
 
 -         xxxx
 
 -     private:
 
 -         xxxx
 
 -     protected:
 
 -         xxxx
 
 - };
 
  复制代码 
 
 
 |   
 
 
 
 |