Hi,
I have a problem calling a constructor with a temporary object; the syntax makes the compiler think it's a function declaration where I only want to instantiate an object... here's a simplified example of what I would like to do...
Code:
class Test1
{
};
class Test2
{
public:
explicit Test2(const Test1 &)
{ }
void function() const
{
return;
}
};
int main()
{
Test2 t2(Test1()); // I want t2 to be a Test2 object, but this syntax
// means "t2 is a function returning a Test2 object
// and taking one argument who is a function returning a
// Test1 object and taking no argument
t2.function(); // error: request for member ‘function’ in ‘t2’, which is
// of non-class type ‘Test2 ()(Test1 (*)())’
return 0;
}
What is the correct syntax to achieve this ?
Thanks