Hello everyone. I'm new to the forum. I have experience in programming in C# and Java, while I don't know how to use C++.
I would like to do something like this... pass an object of type class1 to the constructor of the second object (like class2) as required by the constructor of class2.
How can I do it??? The compiler won't let me do it...
P.s. I know there's something missing in the syntax, but I'm on my phone and I don't feel like writing everything... Can anyone help me?
Below are what I would like to do...
This is in a file.cpp and then the declarations in file.h
OP's use case in Post #1 required the class1 constructor to take an argument: class1 oggClasse1(10);
So such an constructor must be provided.
That's an assignment statement, not an initialization. Probably doesn't make a difference for this trivial example, but it's a vital distinction with more complex classes. OP's use case in Post #1 required a copy constructor: class2 oggClasse2(oggClasse1);
Also, Initialization of member classes must be done in the constructor's initialization list. So: