Hi, coders. I have to overload operators +, *, =. Object L3(default "abc") must be smth like this "aabbcc"(operator*; double each symbol of the string). Then I must concatenate Object2 and Object3(operator+), and initialize Object1(operator = ).
I have strange errors
error C2296: '*' : illegal, left operand has type 'Row *'
error C2297: '*' : illegal, right operand has type 'Row *'
Sorry for my English, I know it's awful. So maybe it will be better if I show the code.
#include "stdafx.h"
#include "row.h"
#include <iostream>
#include <string>
using namespace std;
class Row
{
private:
char *data;
public:
Row();
Row(char* v);
Row(Row &);
Row* operator*(Row *c);
Row* operator+(Row *c);
Row* operator=(Row *h);
int Dimension();
void Out();
};
//*************************/
const int n = 2;
Row::Row()
{
data = NULL;
}
Row::Row(char* v)
{
data = v;
}
Row::Row(Row ©)
{
data = copy.data;
}
int Row::Dimension()
{
int res0 = strlen(data);
return res0;
}
void Row::Out()
{
cout << "stroka: " << data << endl;
}
Row* Row::operator*(Row *c)
{
char *tmp = new char[strlen(data)];
tmp = data;
int len = strlen(data);
for(int i = 0; i < len; i++)
{
tmp[i*2+1] = tmp[i*2] = data[i];
}
Row *res0 = new Row(tmp);
return res0;
}
Row* Row::operator+(Row *c)
{
int len = strlen(data);
char *tmp = new char[len+1];
strcpy(tmp,data);
strcat(tmp,c->data);
Row *res1 = new Row(tmp);
return res1;
}
Row* Row::operator=(Row *h)
{
Row* res3 = new Row(h->data);
//res3 = h;
return res3;
/*********************************/
void main()
{
Row* L3 = new Row("abc");
Row* L2(L3);
Row L1;
L1 = (L3*L3) + L2; // ERRORS
L3->Out();
cout << "length L3: " << L2->Dimension() << endl;
L1.Out();
cout << "length L1: " << L1.Dimension() << endl;
}
Thanks anyway.