Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > polymorphism in c

Reply
Thread Tools

polymorphism in c

 
 
Patrick Guio
Guest
Posts: n/a
 
      05-05-2004

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

 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      05-05-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic polymorphism vs. Static polymorphism Krivenok Dmitry C++ 13 06-01-2006 09:49 AM
Polymorphism in GridView (ASP.Net 2.0) Kevin Lawrence ASP .Net 0 02-16-2006 11:32 AM
polymorphism Tony Morris Java 1 03-07-2004 01:29 AM
Help : Casting after a clone & method polymorphism Osaman Java 2 01-05-2004 03:59 PM
Polymorphism in xml ?? Sony Antony Java 0 08-26-2003 03:37 PM



Advertisments
 



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