我想运行下面的C++代码来理解使用MS Visual Studio 15的类继承。生成并运行代码后,我收到消息说MS VS已停止工作。如果有人能帮助我理解我做错了什么,我会非常感激。需要帮助使用C++类继承
#include<cstdio>
#include<string>
#include<conio.h>
using namespace std;
// BASE CLASS
class Animal {
private:
string _name;
string _type;
string _sound;
Animal() {};
protected:
Animal(const string &n, const string &t, const string &s) :_name(n), _type(t), _sound(s) {};
public:
void speak() const;
};
void Animal::speak() const {
printf("%s, the %s says %s.\n", _name, _type, _sound);
}
// DERIVED CLASSES
class Dog :public Animal {
private:
int walked;
public:
Dog(const string &n) :Animal(n, "dog", "woof"), walked(0) {};
int walk() { return ++walked; }
};
int main(int argc, char ** argv) {
Dog d("Jimmy");
d.speak();
printf("The dog has been walked %d time(s) today.\n", d.walk());
return 0;
_getch();
}
'有人能帮助我了解我做错了什么'你有VS2015 –
服从警告[编译时](http://coliru.stacked-crooked.com/a/b01383841d47037d)钻石问题! –