C++ this declaration has no storage class or type specifier
- 源代码
//vvect.h
vector<int> a = { 1,2,3,4,5 };
a = { 2,3,4,5,6 }; //E0077
a.push_back(); //E0077
//test.h
int a=1; //成功
a=2; //Error E0077
//Orderbook.h
class Orderbook
{
public:
string side;
Orderbook(); //No Error if I define inside constructor
Message m; //No Error while declaring
m.check(side); //Error when I write m. or m->
};
分析:
That code has to go inside a function. Your class definition can only contain declarations and functions.
Classes don't "run", they provide a blueprint for how to make an object.