• Advertisement
Sign in to follow this  

C++ duck typing with optional members

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