gpt4 book ai didi

c++ - 无法正确构图

转载 作者:太空狗 更新时间:2023-10-29 20:25:32 26 4
gpt4 key购买 nike

老实说,我很尴尬,我不得不问,但我坚持这一点。

#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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com