作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
老实说,我很尴尬,我不得不问,但我坚持这一点。
#include <iostream>
using namespace std;
class Obj
{
};
class Test
{
private:
Obj a;
public:
Test(Obj _a)
: a(_a)
{}
};
int main() {
Obj ob();
Test t(ob);
return 0;
我收到这个错误:
t.cpp:24: error: no matching function for call to ‘Test::Test(Obj (&)())’
t.cpp:15: note: candidates are: Test::Test(Obj)
t.cpp:10: note: Test::Test(const Test&)
我不明白。相同的代码片段适用于内置类型(整数和其他东西)。
最佳答案
Obj ob();
将 ob
声明为不带参数并返回 Obj
的函数。
如果您想默认构造一个Obj
,请使用Obj ob;
或Obj ob{};
。
关于c++ - 无法正确构图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23501482/
我正在制作一款基于 JavaFX 的游戏,该游戏使用宇宙飞船射击无人机来保卫您的基地。我想在图像周围包裹一个形状以为其创建一个点击框。 这将使激光在接触碰撞箱时对无人机造成伤害。这将使游戏看起来比激光
我是一名优秀的程序员,十分优秀!