point classes, design of class relation

Discussion in 'C Programming' started by Brice Rebsamen, Apr 3, 2008.

  1. 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
     
    Brice Rebsamen, Apr 3, 2008
    #1
    1. Advertising

  2. Brice Rebsamen writes:
    > 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.

    --
    Hallvard
     
    Hallvard B Furuseth, Apr 3, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ganesh
    Replies:
    3
    Views:
    503
    Rolf Magnus
    May 10, 2005
  2. Aaron Brady

    reverse dict lookup & Relation class

    Aaron Brady, Jan 15, 2009, in forum: Python
    Replies:
    8
    Views:
    395
    Aaron Brady
    Jan 18, 2009
  3. Aaron Brady

    relation class

    Aaron Brady, Apr 22, 2009, in forum: Python
    Replies:
    5
    Views:
    330
    Aaron Brady
    Apr 26, 2009
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,341
    Saraswati lakki
    Jan 6, 2012
  5. John Carter
    Replies:
    1
    Views:
    128
Loading...

Share This Page