I have simplified the class for the sake of question.
Please I need someone to explain the following: when the compiler see
Mystring x{"ABC"};
it will directly trigger the class constructor - this is understood- but how the compiler also trigger the class constructor after the equal sign , I mean how the compiler knows that it needs to constructor an instance of the class with initial value of "Hi there"
Mystring test="Hi there";
`
#include<iostream>
#include<cstring>
class Mystring
{
private:
char * str;
public:
Mystring(char * s)
:str{nullptr}
{
str = new char[std::strlen(s)+1];
std::strcpy(str,s);
std::cout<<"constructor is called for: "<<this->str<<std::endl;
}
};
int main()
{
Mystring x{"ABC"};
Mystring test="Hi there";
return 0;
}
`
It works ok and the compiler were able to create an instance of the class with the initializer of "Hi there" but I need to know how the compiler triggers the class constructor when there is no Mystring class name before the initialization value of "Hi there"