开发者

Compiler Error: "expected specifier-qualifier-list"

int main()
{
    typedef struct a
    {
        static int w;
        char *p;
    } a;
}

on compiling it gives error:expected specifier-qualifier-list before 'static' could u please tell me what this error means and how to开发者_如何学编程 remove it?


Local classes cannot have static data members in C++.

To quote the standard (Paragraph 9.8.4)

A local class shall not have static data members.

In the unlikely case that you don't know, a local class is a class, struct, or union defined in function scope.

9.8.1

A class can be defined within a function definition; such a class is called a local class.


static is a storage class, so it does not properly apply to a typedef. It's along the same lines as register and const.

Even if static worked, how would w be static and p not be static?

This will work though:

int main()
{
    typedef struct a
    {
        int w;
        char *p;
    } a;
    static a a0;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜