Re: Inheriting question...
So C3DPoint inherits C2DPoint publically, and C2DPoint has a + operator defined? In that case, it's not really that strange. Remember that public inheritance means IS-A, and because of that C3DPoint IS-A C2DPoint. This makes the operator + defined for C2DPoint fit perfectly when you add a C2DPoint and a C3DPoint.
To tell you the truth, I don't really think public inheritance is the right relation between the two classes here. A C3DPoint is not a C2DPoint in my opinion. It only looks very similar. At best you could say it HAS-A C2DPoint, in which case you would use a member to model the relationship.
Re: Inheriting question...
Moreover, I don't see how you can naturally add a 2D point to a 3D point...
1 Attachment(s)
Re: Inheriting question...
Quote:
Originally Posted by cilu
Moreover, I don't see how you can naturally add a 2D point to a 3D point...
You just move over x and y coordinates .. z coordinate stays the same.
Quote:
A C3DPoint is not a C2DPoint in my opinion.
C3DPoint just add a z coordinate ... if I create 2D point it is 2D .. if I create 3D point it first create 2D and then add the z coordinate and become 3D....
I attach the source code if you have time to look at it ... I need to know why this happens and how can i prevent that ...
Thanks again :)
Re: Inheriting question...
I have to agree with wien: a 3D point is not a 2D point. This example is similar to the circle/ellipse example of bad inheritance. Just because it looks that way mathematically, doesn't mean that it's a good idea to use inheritance in this way.
Re: Inheriting question...
Quote:
You just move over x and y coordinates .. z coordinate stays the same.
Why not move the y and z coordinates and keep the x unchanged?
Anyway, please use zip to compress files, not rar. Zip is a cross-platform format. For instance, I don't have WinRar, I can't extract your files.
Re: Inheriting question...
Also, aside from the fact that I find it strange having C3DPoint inherit C2DPoint , since these classes will most often be used as values you set yourself up for slicing problems by publically inheriting C2DPoint.
If I have a number of fixed dimensions I would prefer a point (vector) to be a template class with a numerical template parameter that decides the dimension of the point (vector).
Code:
template<std::size_t n>
struct vector
{
// ... methods
double m_vector[n];
};
Re: Inheriting question...
Minor niggle: I wouldn't call it vector, though.
Re: Inheriting question...
Well,
thanks for the answers ... i figured out what i needed ...