秦商越 发表于 2019-9-1 10:08:13

求助!小甲鱼c艹中重继承那个代码!照着打的为什么还有那么多错误orz

#include<iostream>
#include<string>

class Person
{
public:
    Person(std::string theName);

    void introduce();

protected:
    std::string name;
};

class Teacher : public Person
{
public:
    Teacher(std::string theName,std::string theClass);

    void teach();
    void introduce();

protected:
    std::string classes;
};

class Student : public Person
{
public:
    Student(std::string theName,std::string theClass);

    void attendClass();
    void introduce();

protected:
    std::string classes;
};

class TeachingStudent : public Student,public Teacher
{
public:
    TeachingStudent(std::string theName,std::string classTeaching,std::string classAttending);

    void introduce();
};

Person::Person(std::string theName)
{
    name = theName;
}
void Person::introduce()
{
    std::cout << "大家好,我是" << name << "。\n\n";
}

Teacher::Teacher(std::string theName,std::string theClass) : Person(theName)
{
    classes = theClass;
}
void Teacher::teach()
{
    std::cout << name << "教" << classes <<"。\n\n";
}

Student::Student(std::string theName,std::string theClass) : Person(theName)
{
    classes = theClass;
}

void Student::attendClass()
{
    std::cout << name << "加入" << classes << "学习。\n\n";
}
TeachingStudent::TeachingStudent(std::string theName,
                                 std::string classTeachenging,
                                 std::string classAttending) : Teacher(theName,classTeaching),Student(theName,classAttending)
                                 {
                                 }
void TeachingStudent::introduce()
{
   std::cout << "大家好,我是" << Student::name << "。我教" << Teacher::classes ;
   std::cout << " ,同时也在" << Student::classes << "读书" ;
}

int main()
{
    Teacher teacher("张12","入门班");
    Student student("李一一","入门班");
    TeachingStudent zhujiao("张二二","入门班","进阶班");

    teacher.introduce();
    teacher.teach();
    student.introduce();
    student.attendClass();
    zhujiao.introduce();
    zhujiao.teach();
    zhujiao.attendClass();

    return 0;
}
上面是源码-------------------------------------------------------------------------下面是问题-------------------------------------------------------------

error: converting to execution character set: Illegal byte sequence|(错误类型都是这种)

ba21 发表于 2019-9-1 13:03:53

用C++编译 除了TeachingStudent::TeachingStudent(std::string theName,
                                 std::string classTeachenging,
                                 std::string classAttending):Teacher(theName,classTeachenging),Student(theName,classAttending)
                                 {
                                 }

没发像别的错误提示

superbe 发表于 2019-9-1 13:33:53

本帖最后由 superbe 于 2019-9-1 13:36 编辑

TeachingStudent::TeachingStudent(std::string theName,
                                 std::string classTeachenging,
                                 std::string classAttending) : Teacher(theName,classTeaching),Student(theName,classAttending)    //classTeaching和classTeachenging哪个打错了
                                 {
                                 }
好象还缺少Teacher::introduce() 和 Student::introduce()吧,Teacher类和Student类中都有introduce(),是重写了父类Person中的introduce()方法,但是没有定义。

改了这些,再编译看还有什么提示。
页: [1]
查看完整版本: 求助!小甲鱼c艹中重继承那个代码!照着打的为什么还有那么多错误orz