Jump to content
  • Advertisement
Sign in to follow this  
Hodgman

C++ duck typing with optional members

This topic is 1145 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

Advertisement

Nice!!!

 
Some ideas: Put the FindMember classes inside a namespace, e.g. FindMember::Foo instead of FindMember_Foo. Instead of macro TRY_GET_MEMBER, overload operator ->* on these FindMember classes. 
std::vector<DrawItem*>* zpass = view->*FindMember::zpass<std::vector<DrawItem*>();

Share this post


Link to post
Share on other sites

Some ideas: Put the FindMember classes inside a namespace, e.g. FindMember::Foo instead of FindMember_Foo. Instead of macro TRY_GET_MEMBER, overload operator ->* on these FindMember classes. 

std::vector<DrawItem*>* zpass = view->*FindMember::zpass<std::vector<DrawItem*>();

I like it. Added support for this alternate syntax to the OP and used the namespace idea smile.png

[edit] Also wrote another macroless syntax which is quite clean now!

bool found = FindMember::MemberName(object, outputPointer);

Edited by Hodgman

Share this post


Link to post
Share on other sites


But what if you want to try and access a member, and only use it if it actually exists?

 

Then you would use Objective C instead.

Share this post


Link to post
Share on other sites

But what if you want to try and access a member, and only use it if it actually exists?

 
Then you would use Objective C instead.

Everyone knows that Objective C is a myth. What's next, unicorns? laugh.png

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!