what does...

This is a discussion on what does... within the C++ Programming forums, part of the General Programming Boards category; What exactly does xyz (as an example) in var(xyz) do? i have been unable to find anything that might tell ...

If so, it does the exact same thing as
int var = xyz; But only for built-in types
User for user defined types (classes, structs) assigning a variable like this calls the copy constructor, as opposed to the default constructor, and assignment operator.

Originally posted by Eibro But only for built-in types
User for user defined types (classes, structs) assigning a variable like this calls the copy constructor, as opposed to the default constructor, and assignment operator.

...

For built in types, it doesn't matter which way you assign. For user defined types, prefer the first ( var(anothervar) ) as you only invoke a single function call.

That's not true at all!

The = in a declaration with initialization is purely cosmetic. The copy constructor is called, not the default and assignment.

Both explicitly specifying the copy constructor and using = do exactly the same thing.

Its working correctly

Hi Poly,

I had tried this few years ago, when learning copy / default constructor, can't recollect the compiler. It didn't behave this way. So was always wondering why it didn't work the way I had predicted (default first followed by copy), but just tried the same now on MSVC++6 and worked correctly.... hmmmmmmm what more can i say