calling global structs
Im the progress still of porting C++ to C, yes yes yes I know, but ran across another problem.
I'm making each C++ class into a C struct, and I need to know how to inherit another struct like one would inherit a class in C++. Thanks guys! (and gals) |
You can't meld structs together, but you can nest them:
Code:
struct base_struct |
Yea I believe that it is! Let me give it a try. thanks
|
mmmmm let me see if I got this
FILE 1 Code:
struct THEA A Code:
struct THEB B |
You need to declare your structures like:
Code:
struct THEA |
Here's a simple example. Say you're tracking book sales. Every book has a name and a number of pages and so forth. So you set up a book struct like so:
Code:
struct book_base Code:
{ Code:
struct indiv_book Code:
{ Or you could check how many pages book[0] has by looking at book[0].book->num_pages. Clear as mud? :) |
almost but Im trying to set a variable from the first struct not something from the second struct.
|
Then you would do like: book[0].book->name = "new name";
EDIT: Or you could do books[1].name = "new name"; or course if you wanted to change it directly without going through an indiv_book struct instance. |
hi!
ever tried something like this: Code:
struct base_struct I have learned that in C++, structs are EXACTLY like classes except that the default visibility is public instead of private. So, you also could have used classes instead. So long... bruce |
All times are GMT -5. The time now is 06:46 PM. |