Jump to content
  • Advertisement
Sign in to follow this  

Probably a stupid question

This topic is 2221 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently trying to write a library in C, but I've found myself in a situation where using something like polymorphism would save me from a ton of code duplication.

However, I'd also like the library to function perfectly in C++ without requiring the library user to do a ton of casting.

This brings me to one of two solutions:
1) Overload every function that expects the base struct if using a C++ compiler.
2) use inheritance in C++, just make the base struct the first data member in C

#2 seems like the most attractive choice, just due to the number of functions involved. But it also seems as though it could break if the library was initially built in C (or if used in C, would break if the library was initially built in C++), I honestly have no clue.

Any advice?

[edit]Answered the question for myself. Sorry, mods can delete or whatever.

[mod edit]We generally don't delete threads, but prefer to leave them around for others to also learn from. If someone answers their own question, it's appreciated when they share their thoughts for the above reason. Edited by Hodgman

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!