Problem with virtual function...
Hello! =) I have one more problem =/ I must run program like that:
1 2 3 4 5 6 7 8
|
Vector2D V2D;
Vector3D V3D;
cin>>V3D;
cout<<V3D;
Vector2D *pV2D = &V3D;
cout<<(pV2D->GetLength());
getch();
|
but when i'm compiling one error appears:
'GetLength' : is not a member of 'Vector2D' |
but IS a member...
that's code of my program:
cpp:
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <iostream>
#include "Przyklad.h"
using namespace std;
Vector2D::Vector2D():x(3), y(2)
{}
double Vector2D::GetLenght()
{
double lenght=sqrt(x*x+y*y);
return lenght;
}
void Vector2D::Get(istream& in)
{
cout<<endl<<"Podaj wspolrzedna X: ";
in>>x;
cout<<"Podaj wspolrzedna Y: ";
in>>y;
}
void Vector2D::Put(ostream& out)
{
out<<"Wspolrzedna X tego wektora to: "<<x<<endl;
out<<"Wspolrzedna Y tego wektora to: "<<y<<endl;
}
ostream& operator<<(ostream& out, Vector2D& vector)
{
vector.Put(out);
return out;
}
istream& operator>>(istream& in, Vector2D& vector)
{
vector.Get(in);
return in;
}
Vector2D::~Vector2D()
{}
double Vector3D::GetLength()
{
double lenght=sqrt(x*x+y*y+z*z);
return lenght;
}
void Vector3D::Put(ostream& out)
{
out<<"Wspolrzedna X tego wektora to: "<<x<<endl;
out<<"Wspolrzedna Y tego wektora to: "<<y<<endl;
out<<"Wspolrzedna Z tego wektora to: "<<z<<endl;
}
void Vector3D::Get(istream& in)
{
cout<<"Podaj wspolrzedna X: ";
in>>x;
cout<<"Podaj wspolrzedna Y: ";
in>>y;
cout<<"Podaj wspolrzedna Z: ";
in>>z;
}
|
header:
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
|
#include <iostream>
#include <string>
using namespace std;
class Vector2D
{
protected:
double x, y;
public:
Vector2D();
virtual double GetLenght();
virtual void Get(istream& in);
virtual void Put(ostream& out);
friend ostream& operator<<(ostream& out, Vector2D& vector);
friend istream& operator>>(istream& in, Vector2D& vector);
~Vector2D();
};
class Vector3D : public Vector2D
{
protected:
double z;
public:
double GetLength();
void Put(ostream& out);
void Get(istream& in);
};
|
can someone tell me what should i do to compile this prog??
p.s. sorry for my english...
Last edited on
Vector2D has a member called GetLenght, not one called GetLength
HAhaha...how stupid i'm:D thank you...
Topic archived. No new replies allowed.