double int, array operator overloading!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
int main() {
myvector a(2);
myvector b(2);
cout << a.size();
a[0] = 0.0; a[1] = 2.0;
b[0] = 1.0; b[1] = 2.0;
cout<< a[0]<<endl;
myvector e=a+b; //operator+ error!
cout << e << endl;
double g = a.norm();
cout << g << endl;// I want double g, but when I change int>double error!
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
class myvector{
private:
double * arr;
int arrlen;
double xpos, ypos;
public:
myvector();
myvector(int size);
int size();
double norm(); // norm() is double but result int
void resize(int newsize);
double& operator[](int pos)
{
return arr[pos];
}
double& operator+(const myvector &ref)
{
//this part, how to use arr[0], arr[1], return?
}
//////////* myvector.ccp///////////////
double myvector:: norm()
{
double normvalue;
normvalue = (double)sqrt(arr[0]*arr[0] + arr[1]*arr[1]);
return normvalue;
}
*/
|
Is there a question in there somewhere?
did you implemented a assignment operator ? (=) .
Topic archived. No new replies allowed.