#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不,它不 –