The error is that the compiler is unable to convert from type c to c&.
When i convert the code to the following - everything works as planned, however i would like to avoid the extra variable and line of code.

int bar(void)
{
Class temp(param1, param2);
foo(temp);
}

If anyone is able to provide some insight into my "problem" it would be greatly appreciated.
[Edited by - shrtysk8r1 on June 6, 2005 9:33:58 PM]

0

Share this post

Link to post

Share on other sites

I'm assuming you meant "Class" not "c" as argument for the call to foo.

The later versions of GCC claim that its behavior is standards compliant -- you can't have a non-const reference to a temporary object. Microsoft, meanwhile, appears to believe that that's OK. Just re-formulate the code like the latter, and it'll work in both cases.

You get into similar problems when nuking STL containers:

std::container<SomeType> myContainer;

myContainer.swap( std::container<SomeType>() ); // doesn't work on GCC std::container<SomeType>().swap( myContainer ); // works on both