I have a class with one member of type string. I would like to ask how can I use the operator = to assign a string to the newly instantiated object of the given class. I tried defining an operator function but to no avail?
class strtype {
string str;
public:
strtype() {
str = "Test";
}
strtype(string ss) {
str = ss;
}
strtype operator= (strtype &st) {
strtype tmp;
tmp.str = st.str;
return tmp;
}
};
int main(){
//how can i do the following:
strtype b = "example";
}