您的位置:首页 > 其它

C++  error C2629: unexpected 'class B (' 以找到错误点,但不知原因;

2013-12-04 00:29 357 查看
# include <iostream>
# include <string>

using std::endl; using std::cin; using std::cout;
class A{
public:
A(int i):val(i){ cout<<"基类的构造函数"<<endl;  }
virtual ~A(){  cout<<"调用基类的析构"<<endl;};
virtual void get(){  cout<<"val的值:"<<val<<endl;  }
protected:
int val;
};

class B:public A{
public:
B(){  cout<<"派生类B的构造函数"<<endl;  }
B(string s,int i):A(i),str(s){  cout<<"派生类B的构造函数"<<endl;  }
~B(){  cout<<"派生类B的析构函数"<<endl;  }
private:
string str;
};

int main(){
B *b=new B("Hello world!!!",99);
cout<<b->get()<<endl;
delete b;
return 0;
}
error C2629: unexpected 'class B ('在类似的错误中可以将 引用
using std::endl; using std::cin; using std::cout;
修改为
using namespace std;
错误就会消失
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐