I'm honestly embarassed I have to ask but I'm stuck on that.
#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;
}
I get this error:
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&)
I don't get it. The same snippet works just fine with built in types (integers and stuff).
Obj ob();
declares a ob
to be a function taking no parameters and returning Obj
.
If you want to default construct an Obj
, use Obj ob;
or Obj ob{};
.