我想運行下面的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)鑽石問題! –