[Solved] C++ Using Class to Define New Type


Defining a constructor that takes a const char* as parameter and a copy constructor should do it. Having a copy constructor there also means you’d need a copy assignment operator and a destructor. You should also decide whether your objects assume ownership of the strings. In your example – a.value = "Hello, "; – just makes that member point to that string literal. You won’t be able to modify it afterwards – perhaps make a copy there?

However, I must point out the existing std::string implementation that exists in <string>.

2

solved C++ Using Class to Define New Type