这代码看不出是哪错了,编译不了
#include<iostream>#include<string>
using namespace std;
classPeople
{
public:
People(std::stringthename);
protected:
std:: string name;
};
class Man:public People
{
};
People::People(std::string thename)
{
name=thename;
}
int main()
{
Man man("A");
return 0;
}
请问是哪里错了
本帖最后由 螃蟹009 于 2012-11-23 23:26 编辑
#include<iostream>
#include<string>
using namespace std;
classPeople
{
public:
People(std::string thename);
protected:
std::string name;
};
class Man:public People
{
public:
Man(std::string thename);
};
People::People(std::string thename)
{
name=thename;
}
Man::Man(std::string thename):People(thename)
{
}
int main()
{
Man man("A");
man.eat();
return 0;
}你在主函数里的man中设置了参数所以要在子类中添加上参数!你可以在People中设置个输出的函数来检测!
明白了,谢谢 {:1_1:}
页:
[1]