为什么这个不能编译?

发布于 2024-09-26 16:02:35 字数 4174 浏览 7 评论 0原文

我在这里创建了这个类:

//Integer矩形类

class AguiRectangle {
    int x;
    int y;
    int width;
    int height;
public:

    bool isEmpty {

        return x == 0 && y == 0 &&
           width == 0 && height == 0;
    }

    int getTop() {
        return x;
    }
    int getLeft() {
        return y;
    }

    int getBottom() {
        return y + height;
    }
    int getRight() {
        return x + width;
    }

    AguiPoint getTopLeft()
    {
        return AguiPoint(getTop(),getLeft());
    }
    AguiPoint getBottomRight()
    {
        return AguiPoint(this->getBottom(),this->getRight());
    }
};

编译器告诉我 x 和 y 以及宽度和高度等都未声明。就好像班级看不到自己一样。

谢谢

Error   14  error C2673: 'getBottomRight' : global functions do not have 'this' pointers    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   178
Error   16  error C2673: 'getBottomRight' : global functions do not have 'this' pointers    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   178
Error   13  error C2665: 'AguiPoint::AguiPoint' : none of the 4 overloads could convert all the argument types  c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   174
Error   6   error C2628: 'AguiRectangle' followed by 'int' is illegal (did you forget a ';'?)   c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   158
Error   3   error C2473: 'isEmpty' : looks like a function definition, but there is no parameter list.  c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   153
Error   5   error C2238: unexpected token(s) preceding ';'  c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   156
Error   17  error C2227: left of '->getRight' must point to class/struct/union/generic type c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   178
Error   15  error C2227: left of '->getBottom' must point to class/struct/union/generic type    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   178
Error   2   error C2146: syntax error : missing ';' before identifier 'result'  c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   64
Error   19  error C2143: syntax error : missing ';' before '}'  c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   180
Error   21  error C2079: 'pp' uses undefined class 'AguiPointf' c:\Users\Josh\Documents\Visual Studio 2008\Projects\Agui\Alleg_5\main.cpp   35
Error   8   error C2065: 'y' : undeclared identifier    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   162
Error   9   error C2065: 'y' : undeclared identifier    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   166
Error   7   error C2065: 'x' : undeclared identifier    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   159
Error   11  error C2065: 'x' : undeclared identifier    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   169
Error   12  error C2065: 'width' : undeclared identifier    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   169
Error   10  error C2065: 'height' : undeclared identifier   c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   166
Error   4   error C2059: syntax error : 'return'    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   155
Error   18  error C2059: syntax error : '}' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   180
Error   20  error C2059: syntax error : '}' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   180
Error   1   error C2027: use of undefined type 'AguiPointf' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   59

I'v created this class here:

//Integer rectangle class

class AguiRectangle {
    int x;
    int y;
    int width;
    int height;
public:

    bool isEmpty {

        return x == 0 && y == 0 &&
           width == 0 && height == 0;
    }

    int getTop() {
        return x;
    }
    int getLeft() {
        return y;
    }

    int getBottom() {
        return y + height;
    }
    int getRight() {
        return x + width;
    }

    AguiPoint getTopLeft()
    {
        return AguiPoint(getTop(),getLeft());
    }
    AguiPoint getBottomRight()
    {
        return AguiPoint(this->getBottom(),this->getRight());
    }
};

The compiler tells me that x and y and width and height are undeclared among other things. It's almost like the class does not see itself.

Thanks

Error   14  error C2673: 'getBottomRight' : global functions do not have 'this' pointers    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   178
Error   16  error C2673: 'getBottomRight' : global functions do not have 'this' pointers    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   178
Error   13  error C2665: 'AguiPoint::AguiPoint' : none of the 4 overloads could convert all the argument types  c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   174
Error   6   error C2628: 'AguiRectangle' followed by 'int' is illegal (did you forget a ';'?)   c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   158
Error   3   error C2473: 'isEmpty' : looks like a function definition, but there is no parameter list.  c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   153
Error   5   error C2238: unexpected token(s) preceding ';'  c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   156
Error   17  error C2227: left of '->getRight' must point to class/struct/union/generic type c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   178
Error   15  error C2227: left of '->getBottom' must point to class/struct/union/generic type    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   178
Error   2   error C2146: syntax error : missing ';' before identifier 'result'  c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   64
Error   19  error C2143: syntax error : missing ';' before '}'  c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   180
Error   21  error C2079: 'pp' uses undefined class 'AguiPointf' c:\Users\Josh\Documents\Visual Studio 2008\Projects\Agui\Alleg_5\main.cpp   35
Error   8   error C2065: 'y' : undeclared identifier    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   162
Error   9   error C2065: 'y' : undeclared identifier    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   166
Error   7   error C2065: 'x' : undeclared identifier    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   159
Error   11  error C2065: 'x' : undeclared identifier    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   169
Error   12  error C2065: 'width' : undeclared identifier    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   169
Error   10  error C2065: 'height' : undeclared identifier   c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   166
Error   4   error C2059: syntax error : 'return'    c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   155
Error   18  error C2059: syntax error : '}' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   180
Error   20  error C2059: syntax error : '}' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   180
Error   1   error C2027: use of undefined type 'AguiPointf' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\Agui\AguiBaseTypes.h   59

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等数载,海棠开 2024-10-03 16:02:35

应该

bool isEmpty()

代替

bool isEmpty

should be

bool isEmpty()

instead of

bool isEmpty
梓梦 2024-10-03 16:02:35

您是否应该使用 bool isEmpty() { ... }

Should you be using bool isEmpty() { ... }

任性一次 2024-10-03 16:02:35

我发现的第一个错误

bool isEmpty {

应该是

bool isEmpty() const {

first error I could find is

bool isEmpty {

should become

bool isEmpty() const {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文