鱼C论坛

 找回密码
 立即注册
查看: 708|回复: 1

[已解决]c++类与对象

[复制链接]
发表于 2021-12-15 20:47:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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那里,就自己按小甲鱼要求写了个程序,结果老是报错,看了几小时了。这程序快把我这个新手搞死了。大佬们帮我这个新手看看,感激不尽!
最佳答案
2021-12-15 23:04:08
1.)C++ 用头文件 include <iostream> 就不要多此一举 include <cstdio>
2.)请检查你的类构造(为什么有那么多花括号?),正确构造:
class xxxx
{
    public:
        xxxx
    private:
        xxxx
    protected:
        xxxx
};
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-12-15 23:04:08 | 显示全部楼层    本楼为最佳答案   
1.)C++ 用头文件 include <iostream> 就不要多此一举 include <cstdio>
2.)请检查你的类构造(为什么有那么多花括号?),正确构造:
class xxxx
{
    public:
        xxxx
    private:
        xxxx
    protected:
        xxxx
};
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-23 07:22

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表