Probably a stupid question

Started by
-1 comments, last by nfries88 11 years, 8 months ago
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.

This topic is closed to new replies.

Advertisement