C++ error:conflicting declaration

#include<iostream>#include<string>usingnamespacestd;classstudent{stringname;public:st... #include <iostream>
#include <string>
using namespace std;
class student
{
string name;
public:
student(string n):name(n)
{
cout<<"registering student "<<n<<endl;
}
};

class subject
{
int score;
string name;
public:
subject(string n,int s):name(n),score(s)
{
cout<<"subject "<<n<<endl
<<"score "<<s<<endl;
}
};

int main()
{
string n;
cin>>n;
int s;

cin>>s;

student(n);
subject(n,s);

return 0;
}
main函数里
subject 那句执行是没有问题的
但是 student 那句执行的时候就报错了
但是我把student(n)换成student("name")之类的又是可以运行的
展开
 我来答
匿名用户
2020-04-25
展开全部
我也不会,有点太难了;
#include <iostream>
using namespace std;
class beijing;
class shanghai
{
public:
shanghai(int a,int b,int c)
{
benchi=a;
baoma=b;
aodi=c;
total=benchi+baoma+aodi;
}
int get_total()
{
return total;
}
friend int count (beijing b,shanghai s);
private:
int aodi,benchi,baoma,total;

};
class beijing
{
public:
beijing(int a,int b,int c)
{
benchi=a;
baoma=b;
aodi=c;
total=benchi+baoma+aodi;
}
int get_total()
{
return total;
}
friend int count(beijing b,shanghai s);
private:
int aodi,benchi,baoma,total;

};

int count(beijing b,shanghai s)
{
return b.total+s.total;
}
int main()
{
int a,b,c,d,e,f;
cout<<"上海的车奔驰(a)宝马(b)奥迪(c)"<<endl;
cin>>a>>b>>c;
cout<<"北京的车奔驰(d)宝马(e)奥迪(f)"<<endl;
cin>>d>>e>>f;
shanghai s(a,b,c);
beijing b(d,e,f);
cout<<"the total count of shanghai is: "<<s.get_total()<<endl;
cout<<"the total count of beijing is: "<<b.get_total()<<endl;
cout<<"the total count of shanghai and beijing is: "<<count(b,s)<<endl;

}
我这也错了
希安斯
2025-02-13 广告
希安斯贸易(上海)有限公司的CRC PR2043产品,是我们精心打造的一款高性能产品。该产品采用了先进的技术和优质材料,确保了其在应用中的稳定性和可靠性。CRC PR2043不仅具有出色的性能表现,还具备易于操作和维护的特点,能够满足广大客... 点击进入详情页
本回答由希安斯提供
veket的小号
2014-10-01 · TA获得超过3371个赞
知道大有可为答主
回答量:3762
采纳率:0%
帮助的人:4078万
展开全部
直接调构造函数是不行滴........
student a(n);
subject b(n,s);
你得实例化对象
追问
额(⊙o⊙)…对哦。。。。太感谢了!
那为什么subject那个可以运行的?我好想也没写实例化对象
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式