#include <iostream>
#include <string>
using namespace std;
// your code
class Dog {
public:
int age;
string name, race, voice;
Dog(int new_age,string new_name,string new_race,string new_voice);
void PrintInformation();
void Bark();
};
Dog::Dog(int new_age,string new_name,string new_race,string new_voice) {
age = new_age;
name = new_name;
race = new_race;
voice = new_voice;
}
void Dog::PrintInformation() {
cout << "Name: " << name;
cout << "\nAge: " << age;
cout << "\nRace: " << race << endl;
}
void Dog::Bark(){
cout << voice << endl;
}
int main()
{
Dog buffy(2, "Buffy", "Bulldog", "Hau!!!");
buffy.PrintInformation();
cout << "Dog says: " << buffy.Bark();
}
我是C++中的新手,我无法弄清错误。我在buffy.Bark()看到错误,它似乎像它无法打印返回无效的东西。std :: operator中的“operator <<”不匹配
在标准::操作者< <>(&的std :: COUT),((常量字符)
类型的表达式的值的'buffy.Bark()'是'功能::狗的Bark'返回类型。这种类型看起来是可打印的吗? –
@Kerrek Sb不,它不 –