簡體   English   中英

C ++錯誤-C2228,標識符無法識別為類

[英]C++ error - C2228, identifier not recognized as class

以下是相關代碼:

Canvas.cpp


    #ifndef CANVAS
    #define CANVAS

    #include "graphicsDatatypes.h"

    class Canvas
    {
    private:

        // Current and next points to draw to
        struct cartesianPoint currentPoint, nextPoint;

    public:

        Canvas::Canvas() { numLinesDrawn = 0; };
        Canvas::~Canvas();  

        struct cartesianPoint getCurrentPoint() { return currentPoint; };

        void setCurrentPoint(int x, int y)
        {
            currentPoint.x = x;
            currentPoint.y = y;
        }


    };

#endif

main.cpp


#include "glut-3.7.6-bin\glut.h"
#include "Canvas.cpp"

// Window size
int winWidth, winHeight;

// User's drawing space - current maximum of 4000 lines
Canvas userDrawSpace();

void callbackMouse(int button, int state, int x, int y)
{
    userDrawSpace.setCurrentPoint(x, y);
}

我收到的錯誤是-錯誤C2228:“。setCurrentPoint”的左側必須具有class / struct / union

知道為什么嗎? 該類的定義非常明確,並且應該只包含文本。 當我用鼠標懸停在Canvas上時,Visual Studios意識到Canvas是一類,所以我不知道發生了什么。 任何幫助表示贊賞,謝謝。

Canvas userDrawSpace();

看起來應該創建Canvas對象,但實際上它聲明了一個名為userDrawSpace的函數,該函數返回Canvas對象:-(。

這是C ++中非常常見的陷阱。

只需擺脫(),就可以了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM