付笑 发表于 2012-11-23 22:10:15

这代码看不出是哪错了,编译不了

#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:25:24

本帖最后由 螃蟹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中设置个输出的函数来检测!

付笑 发表于 2012-11-24 00:05:17

明白了,谢谢

刘力 发表于 2012-11-24 12:07:53

阔怀 发表于 2015-8-27 15:58:27

{:1_1:}
页: [1]
查看完整版本: 这代码看不出是哪错了,编译不了