Proper 'using' syntax for pointer-to-member variable

Viewed 54
  struct MyStruct {
    typedef int MyStruct::*Ptr;  // my pointer-to-member type
    int foo, bar;
  };

This code works, but I'd like to bring it up-to-date with modern style and replace the typedef with a using. What's the right syntax to use? I've tried a bunch of options and I'm stuck; the only examples I can find are for pointer-to-member-function which is different.

2 Answers

The using syntax just moves the identifier placement, the general case is that

typedef ............. foo ..............;

can be changed to

using foo = .............  .............;

Your case is no exception; the code could be using Ptr = int MyStruct::*;

using Ptr = int (MyStruct::*);

And in general, (MyStruct::*) will appear wherever * appears in non-member pointers.

Related