Erius
Erius

Reputation: 1031

Template syntax question regarding member variable offsets

I'm using Luabind to integrate LUA into one of my projects, and the following thing struck me as odd (I'm a self taught beginner)

  template <class C, class D, class GetPolicies, class SetPolicies>
        class_& def_readwrite(
            const char* name
          , D C::*mem_ptr
          , GetPolicies const& get_policies
          , SetPolicies const& set_policies
        )

this function takes a string and a pointer to a member field, I get that, what confuses me is the order here.

D C::*mem_ptr

I expected D::C *, since "&foo::bar" into "foo bar:: *" ...looks very odd to me. What is the logic behind this?

Upvotes: 0

Views: 120

Answers (1)

Xeo
Xeo

Reputation: 131799

if you substitute D and C with actual types, it makes sense:

struct Test{
  int member;
};

typedef int Test::*memptr;
//      ^^^ ^^^^
//       D   C
memptr p = &X::member;

Upvotes: 1

Related Questions