Now, does "int b = a;" create a copy of the entire object and all it's members or just "22"? If it creates a copy of the entire thing I guess it can slow things down if I have alot of copies instead of pointers/ref in my program?
Also..
If I change the value of "a" to "3" (a = 3) the constructor gets called. Is that the only thing that happens or is the entire object recreated then reassigned?
If you need a copy, do a copy.
If a copy makes things simpler, consider doing a copy.
If a copy is cheap, consider relaxing.
If your program is slow, look at the bottleneck.
> does "int b = a;" create a copy of the entire object and all it's members or just "22"?
¿what members do you think an int have?
> I guess it can slow things down
measure
> If I change the value of "a" to "3" (a = 3) the constructor gets called.
no.
integers in c++ maybe you can think of them as a CPU hardware register, not a high level programming object. They are just raw bytes that sit in memory and represent a value. They have no methods. C++ adds a layer or two, like type safety (you will get a warning if you put a double into an int, because it drops the decimals, for example) but this is just a compiler AI/detection/warning algorithm, and has no effect on your code or run-time.
copying an int, then, is as efficient as it can be in the CPU/assembly instructions for your hardware, in c++. Its not like python, where you traverse a linked list to copy an integer.
this is why there are so many integer types. Its close to 100 if you count common platform names + language names + C inherited names and so on :P you have a name for signed 1,2,4,8 byte ints and unsigned 1,2,4,8 byte ints (and some systems now have 16 byte ints), and then a number of copies of these for historical reasons
Line 18: The constructor of the object x is not called. What happens is that an unnamed temporary variable of type x1 is created with the value 88 and assigned to x
If it creates a copy of the entire thing I guess it can slow things down if I have alot of copies instead of pointers/ref in my program?
You don't need to worry too much about copying a few hundreds or thousands bytes. This is usually not significant. Except you doing it a lot of times. Premature optimization is usually not a good thing to do.
Line 18: The constructor of the object x is not called. What happens is that an unnamed temporary variable of type x1 is created with the value 88 and assigned to x
That's strange, because when removing "z = length" inside the constructor the output of "x.z" is the initial value (0) instead of "88". That should mean that "88" goes through the constructor, when typing "x = 88".