and how can I use it in a program. For example I want to assign two strings with using a class that I made.
myclass x("string1,string2");
and how can I use it in a program. For example I want to assign two strings with using a class that I made.
myclass x("string1,string2");
eh? Okay, I think I understand. Are you asking about constructor overloading?
Example
Code:class MyClass { protected: std::string str1, str2; public: MyClass(std::string str1, std::string str2) { this->str1 = str1; this->str2 = str2; } };
I think you want to make a constructor that creats an object that is equal to another object, if that's what you want, you should do the following:
You have to creat a constructor that takes an object of the same class as argument, and make the new object equal to the one given as argument.
none...
im pretty sure that's all a copy constructor is, one that needs the copy of one object to instanciate another. That topic should be covered in a C++ book if you have access to one.
A copy constructor for a class named myclass would look like the following:
myclass::myclass(const myclass &mc), m_var1(mc.m_var1), m_var2(mc.m_var2) { /* Other stuff */ };
myclass x("string1","string2"); is not a copy constructor... it doesn't take an argument of myclass.