C ++:无法使用'void'类型的右值初始化'guiBaseObject *'类型的变量

时间:2015-04-15 11:54:53

标签: c++ initialization void openframeworks rvalue

我正在使用openframeworks。这是基于C ++。

我有以下代码:

guiBaseObject *item = panel.addSlider("motor_speed", 0, 0, 100);

我无法理解为什么会收到以下错误。

/Users/CREATER/Documents/of_v0.8.4_osx_release/apps/myApps/MapamokStepper/src/MotorControl.cpp:38:20: Cannot initialize a variable of type 'guiBaseObject *' with an rvalue of type 'void'

2 个答案:

答案 0 :(得分:1)

如果您想要访问滑块,可以执行以下操作:

ofIntSlider motorSpeed;
panel.add(motorSpeed.setup("motor_speed", 0, 0, 100));

答案 1 :(得分:-1)

C ++是一种强类型语言。你真的需要将rvalue转换为左值。 在你的情况下,它应该是:

guiBaseObject *item = (guiBaseObject *)panel.addSlider("motor_speed", 0, 0, 100);

否则会产生编译时错误。

相关问题