Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: error C2679: binary '

Darien Miller:

So i tried re-implementing my own string class using smart pointers just so I can practice integrating them into my daily use. Sadly, I've hit a wall, and I can't figure out why I'm unable to concatenate two "mystring" objects. Any suggestions? Also, if this type of program isn't the proper situation to use smart pointers in, I would also appreciate advice related to that as well.


#include
#include
#include

using namespace std;

class mystring {
public:
mystring() : word(make_unique('\0')), len(0) {}
~mystring() { cout mystring(const char *message) : word(make_unique(strlen(message) + 1)), len(strlen(message)) {
for (int i = 0; i }
mystring(const mystring &rhs) : word(make_unique(rhs.len)), len(rhs.len + 1) {
for (int i = 0; i }
mystring &operator=(mystring &rhs) {
if (this != &rhs) {
char *temp = word.release();
delete[] temp;
word = make_unique(rhs.len + 1);
len = rhs.len;
for (int i = 0; i }
return *this;
}
mystring &operator=(const char *rhs) {
char *temp = word.release();
delete[] temp;
word = make_unique(strlen(rhs)+ 1);
len = strlen(rhs);
for (int i = 0; i
return *this;
}
friend mystring operator+(const mystring& lhs, const mystring& rhs) {
mystring Result;
int lhsLength = lhs.len, rhsLength = rhs.len;

Result.word = make_unique(lhsLength + rhsLength + 1);
Result.len = lhsLength + rhsLength;
for (int i = 0; i for (int i = lhsLength; i
return Result;
}
friend ostream &operator for (int i = 0; i return os;
}
private:
int len;
unique_ptr word;
};

int main()
{
mystring word1 = "Darien", word2 = "Miller", word3;

cout word3 = word1 + word2;//error message: no binary '=' found
cout return 0;
}



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: error C2679: binary '

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×