point classes, design of class relation

B

Brice Rebsamen

I would like to work with points in space:
Point2D : (x,y)
Point3D : (x,y,z)
Pos2D : (x,y,yaw)
Pos6D : (x,y,z,roll,pitch,yaw)

what would be nice is that I can pass a Pos6D to a function that takes
a Point3D as argument. What would be the best way of doing that?

Possibilities I can see are:

1) Point2D is base class of Pos2D which is base class of Pos6D. That's
what I was doing untill I introduced the Point3D class. If Point3D
inherits from Point2D and If Pos6D inherits from both Point3D and
Pos2D then there is ambiguity. Can I solve that?

2) make this classes independent and define constructors and cast
operator to convert between them?

Thanks
Brice
 
H

Hallvard B Furuseth

Brice said:
1) Point2D is base class of Pos2D which is base class of Pos6D.

C does not have classes, let alone base classes. Try comp.lang.c++.
Though C does allow a hack: If two structs start with the same
members, you can cast a pointer to one of the structs to a pointer
to the other and access the common members that way. Usually
it's better to avoid such hacks, however.
2) make this classes independent and define constructors and cast
operator to convert between them?

Nor does C have constructors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top