learn new C++ everyday

I don't remember when I wrote my first C++ program but it was probably about 15 years ago now.

Despite feeling like I know *a lot* about how C++ works, I have to admit, I occasionally stumble upon features I never even knew were there.

Do you know all about C++ namespaces? I always thought that knowing about aliasing made me cool:
namespace OriginalName { void SomeFunction(); } namespace MyName=OriginalName; //... MyName::SomeFunction();
But I just stumbled upon selective namespace export:
using OriginalName::SomeFunction; //... SomeFunction();
Who knew?

Related: I keep meaning to write a post about my recent re-discovery of member pointers. While member method pointers are old hat, I can't remember the last time I've used pointers to simple members -- and yet, last week I needed them on two completely unrelated tasks.....
typedef SomeMemberType SomeClassType::*MemberPtr;
It gives you a way to select and pass around a specific member from a class, without needing an actual instance of that class. It's like using offsetof() but typesafe, and, once you get the typedef in place, much more readable.

At any rate... more on that later.

0 comments: