Is there any process in c++ by using which I can initialize my class object after declare where my class has parameterized constructor .
For example :
class myclass{
private:
string name;
public:
myclass(){
name="No Name";
}
myclass(string iname){
name= iname;
}
};
int main()
{
myclass abc;//we know this will call our default constructor .
myclass aab("name");//this will call our parameterized constructor .
}
Now my question is if C++ has any way so that i can call my parameterized constructor before declare my class object.
for simplicity my question is quiet similar like below code
i want to find any way so that i can call like below
int main()
{
myclass hello;
hello("name");//i want to call my parameterized constructor here.
}
is there any process like that please tell me that
Use a setName method because the object hello has already been instantiated/constructed and you can’t have 2 hello objects. Why would you even if it was possible?
Thanks bro
This two method are working
But for the first method it's call the default constructor
if i want to call 2nd constructor instead of default constructor is there any process @coder777 bro?
and for the second method it's call both default constructor and 2nd constructor with parameter
is there any process to to call only single constructor with the same process @me555 bro??