polymorphism in c

Discussion in 'C Programming' started by Patrick Guio, May 5, 2004.

  1. Patrick Guio

    Patrick Guio Guest

    Dear all,

    I wonder whether it is possible to simulate simple polymorphism in C?
    I explain what I would like to do. I have defined several structures
    mapping different header formats. They all have the same size but have
    different fields.
    So I have something like struct header1, header2 and so on. Now my
    question is how would you define/create an array that can contains
    pointers to header1, header2 and so on?
    Sincerely,
    Patrick
    Patrick Guio, May 5, 2004
    #1
    1. Advertising

  2. Patrick Guio

    Richard Bos Guest

    Patrick Guio <> wrote:

    > I wonder whether it is possible to simulate simple polymorphism in C?
    > I explain what I would like to do. I have defined several structures
    > mapping different header formats. They all have the same size but have
    > different fields.
    > So I have something like struct header1, header2 and so on. Now my
    > question is how would you define/create an array that can contains
    > pointers to header1, header2 and so on?


    Porbably the best solution would be to use a union (in your case, an
    array of unions). Then your main worry would be to determine which kind
    of struct any one union currently contains, which can easily be solved
    by adding a type member as the first member of each struct.

    Richard
    Richard Bos, May 5, 2004
    #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. Kevin Lawrence

    Polymorphism in GridView (ASP.Net 2.0)

    Kevin Lawrence, Feb 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    842
    Kevin Lawrence
    Feb 16, 2006
  2. Sony Antony

    Polymorphism in xml ??

    Sony Antony, Aug 26, 2003, in forum: Java
    Replies:
    0
    Views:
    554
    Sony Antony
    Aug 26, 2003
  3. Osaman
    Replies:
    2
    Views:
    441
    John C. Bollinger
    Jan 5, 2004
  4. Tony Morris

    polymorphism

    Tony Morris, Mar 7, 2004, in forum: Java
    Replies:
    1
    Views:
    724
    sonali
    Mar 7, 2004
  5. Krivenok Dmitry
    Replies:
    13
    Views:
    1,431
    Axter
    Jun 1, 2006
Loading...

Share This Page