Copy assignment operator, the rule of three [on hold]











up vote
-2
down vote

favorite












Did I understand it right, that I need a copy assignment operator here according to the rule of three (https://en.cppreference.com/w/cpp/language/rule_of_three)? If yes, can I write it like this: mystring& operator=(mystring other)?



struct mystring {
char *text;
int len;
mystring(const char *txt) {
len=strlen(txt);
text=new char[len+1];
strcpy(text,txt);
}
mystring(const mystring &s) {
len=s.len;
text=new char[len+1];
strcpy(text,s.text);
}
~mystring() {
delete text;
}
void append(const char*);
char &at(int i) {return text[i];};
void print() {cout<<text<<endl;}
};
void mystring::append(const char *txt) {
char *tmp=new char[len+strlen(txt)+1];
strcpy(tmp,text);
strcat(tmp,txt);
delete text;
text = tmp;
}









share|improve this question







New contributor




someone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by πάντα ῥεῖ, Daniel, 200_success, hoffmale, Jamal 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, hoffmale, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    It seems like you are asking us to review an assignment operator that you haven't implemented yet.
    – 200_success
    2 days ago















up vote
-2
down vote

favorite












Did I understand it right, that I need a copy assignment operator here according to the rule of three (https://en.cppreference.com/w/cpp/language/rule_of_three)? If yes, can I write it like this: mystring& operator=(mystring other)?



struct mystring {
char *text;
int len;
mystring(const char *txt) {
len=strlen(txt);
text=new char[len+1];
strcpy(text,txt);
}
mystring(const mystring &s) {
len=s.len;
text=new char[len+1];
strcpy(text,s.text);
}
~mystring() {
delete text;
}
void append(const char*);
char &at(int i) {return text[i];};
void print() {cout<<text<<endl;}
};
void mystring::append(const char *txt) {
char *tmp=new char[len+strlen(txt)+1];
strcpy(tmp,text);
strcat(tmp,txt);
delete text;
text = tmp;
}









share|improve this question







New contributor




someone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by πάντα ῥεῖ, Daniel, 200_success, hoffmale, Jamal 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, hoffmale, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    It seems like you are asking us to review an assignment operator that you haven't implemented yet.
    – 200_success
    2 days ago













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











Did I understand it right, that I need a copy assignment operator here according to the rule of three (https://en.cppreference.com/w/cpp/language/rule_of_three)? If yes, can I write it like this: mystring& operator=(mystring other)?



struct mystring {
char *text;
int len;
mystring(const char *txt) {
len=strlen(txt);
text=new char[len+1];
strcpy(text,txt);
}
mystring(const mystring &s) {
len=s.len;
text=new char[len+1];
strcpy(text,s.text);
}
~mystring() {
delete text;
}
void append(const char*);
char &at(int i) {return text[i];};
void print() {cout<<text<<endl;}
};
void mystring::append(const char *txt) {
char *tmp=new char[len+strlen(txt)+1];
strcpy(tmp,text);
strcat(tmp,txt);
delete text;
text = tmp;
}









share|improve this question







New contributor




someone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Did I understand it right, that I need a copy assignment operator here according to the rule of three (https://en.cppreference.com/w/cpp/language/rule_of_three)? If yes, can I write it like this: mystring& operator=(mystring other)?



struct mystring {
char *text;
int len;
mystring(const char *txt) {
len=strlen(txt);
text=new char[len+1];
strcpy(text,txt);
}
mystring(const mystring &s) {
len=s.len;
text=new char[len+1];
strcpy(text,s.text);
}
~mystring() {
delete text;
}
void append(const char*);
char &at(int i) {return text[i];};
void print() {cout<<text<<endl;}
};
void mystring::append(const char *txt) {
char *tmp=new char[len+strlen(txt)+1];
strcpy(tmp,text);
strcat(tmp,txt);
delete text;
text = tmp;
}






c++ object-oriented






share|improve this question







New contributor




someone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




someone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




someone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









someone

1




1




New contributor




someone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





someone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






someone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by πάντα ῥεῖ, Daniel, 200_success, hoffmale, Jamal 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, hoffmale, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by πάντα ῥεῖ, Daniel, 200_success, hoffmale, Jamal 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, hoffmale, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    It seems like you are asking us to review an assignment operator that you haven't implemented yet.
    – 200_success
    2 days ago














  • 2




    It seems like you are asking us to review an assignment operator that you haven't implemented yet.
    – 200_success
    2 days ago








2




2




It seems like you are asking us to review an assignment operator that you haven't implemented yet.
– 200_success
2 days ago




It seems like you are asking us to review an assignment operator that you haven't implemented yet.
– 200_success
2 days ago















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Morgemoulin

Scott Moir

Souastre