【发布时间】:2016-11-27 07:10:33
【问题描述】:
项目范围:学术
预期目的:有一个用于项目提交的 GUI。这个问题涉及使图形窗口的定义区域可点击。我不熟悉其他图形库。
我在该站点的其他地方查看并阅读了有关此错误的类似帖子:“对非常量的引用的初始值必须是左值。”我真的需要一些进一步的解释来解决这个问题:
#include "graph1.h"`
displayPNG("solve.png", 560, 120);
int x2 = 560 + 54;
int x1 = 560;
int y1 = 120;
int y2 = 291 + 120;
const int * xSolv2 = &x2;
const int * xSolv1 = &x1;
displayPNG("exit.png",545,415);
//Game (loop) play for buttons, options & clickables.
//while (true){
if (leftMouse((xSolv2 > xSolv1) && (x1 < &x2), (&y2 > &y1) && (&y1 < &y2))) //error: "Initial value of reference to non-const must be an lvalue."
{
cout << "Test button functions properly" << endl;
}
我尝试了以下变体,但没有成功。
//shortened for brevity purposes.
bool function (&x,&y)
bool function (*x,*y) // I had created some pointer var(s) earlier and initialized them.
bool function(x, y)
如果有人有在graphicLib2015.lib 中使用“graph1.h”的经验,我很想学习。
【问题讨论】:
-
x1 < &x2为什么要将值与地址进行比较? -
(&y2 > &y1) && (&y1 < &y2)这也是(&y1 < &y2)的一种很冗长的说法 -
小建议:例如,如果您定义
x2 = x1 + 54;,代码将更容易更改。 -
谷歌搜索“graphicLib2015”时的感觉让我回到了同样的 StackOverflow 问题
标签: c++ user-interface graphics lvalue