Can we call the constructor later in the code? For example i create my object now and later i call the constructor?
Just to be clear: a constructor is not a function in C++. It's a constructor.
You can not call a constructor (directly). You can construct an object, which will invoke a constructor as a part of the process. There are various types of constructors, some of which can be created by default if you do not supply your own or instruct the compiler not to do so on its own. It's important to learn the types of constructors and where and how they're used and when they're defaulted.
MainClass mainClass(SecondClass secondClass(1,4));
That's not valid syntax. You can construct a temporary SecondClass object and pass that as an argument like this.
MainClass mainClass(SecondClass(1,4));
Notice that that constructs an unnamed temporary SecondClass object, so your original code would still not compile because you can not take a reference of an unnamed temporary. You would need to declare your MainClass constructor like this.
MainClass(SecondClass const& secondClass)
: secondClass(secondClass)
{
// stuff
}
The const there is very important, since you can take a const reference to an unnamed temporary.
What ends up happening there is the unnamed temporary you created as an argument gets copied (using SecondClass' copy constructor) into the secondClass member variable of the MainClass object. If you're lucky, the optimiser will elide the copy and construct the object directly in place (ie. skips the copy entirely), but the copy constructor still needs to be visible -- and the default copy constructor is visible.