expected asm or __attribute__ before CRenderContext

元气小坏坏 提交于 2019-12-11 06:18:34

问题


I am developing a small app under Linux using the CodeBlocks IDE. I have defined a class with the following code:

class CRenderContext
{
public:     /*instance methods*/
             CRenderContext() :
             m_iWidth(0), m_iHeight(0),
             m_iX(0), m_iY(0),
             m_bFullScreen(false), m_bShowPointer(false) {};

             CRenderContext  (int                    iWidth,
                              int                    iHeight,
                              int                    iX,
                              int                    iY,
                              bool                   bFullScreen,
                              bool                   bShowPointer)
                              :
                              m_iWidth(iWidth), m_iHeight(iHeight),
                              m_iX(iX), m_iY(iY),
                              m_bFullScreen(bFullScreen), m_bShowPointer(bShowPointer) {};
        virtual ~CRenderContext () {};

    public:     /*instance data*/
        int     m_iWidth;
        int     m_iHeight;
        int     m_iX;
        int     m_iY;
        bool    m_bFullScreen;
        bool    m_bShowPointer;
};

I always get the following error when compiling the above code:

error: expected '=', ',', ';', 'asm' or 'attribute' before CRenderContext

Any ideas about how to solve the error?

Thanks in advance,

Eugenio


回答1:


You are compiling it as C code, not C++. You probably need to rename the source file to have a .cpp extension. The code compiles perfectly (as C++) with g++ and comeau, although you have some superfluous semicolons. For example:

virtual ~CRenderContext () {};

No need for the semicolon ot the end there.



来源:https://stackoverflow.com/questions/990578/expected-asm-or-attribute-before-crendercontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!