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;
}
c++ object-oriented
New contributor
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.
add a comment |
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;
}
c++ object-oriented
New contributor
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
add a comment |
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;
}
c++ object-oriented
New contributor
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
c++ object-oriented
New contributor
New contributor
New contributor
asked 2 days ago
someone
1
1
New contributor
New contributor
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
2
It seems like you are asking us to review an assignment operator that you haven't implemented yet.
– 200_success
2 days ago