返回信息流#include<iostream.h>
enum BREED{GOLDEN,CAIRN,DANDIE,SHETLAND,DOB,LAB};
class Mammal
{
public:
Mammal():itsAge(2),itsWeight(5){}
~Mammal(){}
int GetAge() const {return itsAge;}
void SetAge(int age) {itsAge=age; }
int GetWeight() const {return itsWeight;}
void SetWeight(int weight) {itsWeight=weight;}
void Speak() const {cout<<"mammal sound.\n";}
void Sleep() const {cout"shhh,I am sleeping.\n";}
protected:
int itsAge;
int itsWeight;
};
class Dog: public Mammal
{
public:
Dog():itsBreed(GOLDEN){}
~Dog(){}
BREED GetBreed() const {return itsBreed;}
void SetBreed(BREED breed){itsBreed=breed;}
void WagTail() const {cout"tail....";}
void BegForFood() const {cout<<"Begging for food..";}
protected:
BREED itsBreed;
};
int main()
{
Dog Fidio;
Fidio.Speak();
Fidio.WagTail();
cout<<"Fidio is "<<Fidio.GetAge()<<"years old"<<endl;
return 0;
}
编译错误说在Viod Sleep()前面发生这种错误:error C2143: syntax error : missing ';' before 'string'
这是一条镜像帖。来源:北邮人论坛 / cpp / #44231同步于 2010/9/25
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
syntax error : missing ';' before 'string' 请高手指教 [求助
houmeng
2010/9/25镜像同步9 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
include "xxx.h"是可以的
如果这样写,下边就不能用namespace了;
这个主要问题还是cout,他可不是一个函数啊 cout“xxxxx”,没有运算符啊
【 在 ericyosho 的大作中提到: 】
: 你还是好好找本靠谱的书看吧。
: C++里面,竟然还能 include xx.h 的么?
: --
: ...................
re...
还有前面那个头文件也是个(潜在)问题...
【 在 potatossss (薯仔) 的大作中提到: 】
: void Sleep() const {cout"shhh,I am sleeping.\n";}
: 是說這行嗎?cout的操作符呢?<< ...
void Speak() const {cout<<"mammal sound.\n";}
void Sleep() const {cout"shhh,I am sleeping.\n";} //少了"<<"认真点,下边某行也这样