2

Some days ago I looked at boost sources and found interesting typedef.

There is a code from "boost\detail\none_t.hpp":

namespace boost {

namespace detail {

struct none_helper{};

typedef int none_helper::*none_t ;

} // namespace detail

} // namespace boost

I didn't see syntax like that earlier and can't explain the sense of that.

This typedef introduces name "none_t" as pointer to int in boost::detail namespace.

What the syntax is?

And what difference between "typedef int none_helper::*none_t" and for example "typedef int *none_t" ?

mt_serg
  • 7,487
  • 4
  • 29
  • 45

3 Answers3

3

The syntax is for a pointer to member - here it typedefs none_t as a pointer to an int data member of none_helper.

The syntax can be used e.g. this way:

 struct X { int i; };

 typedef int X::*PI;
 PI pi = &X::i;
 X* x = foo();
 x->*pi = 42;

InformIT has an article on member pointers, containing more details.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
1
  • typedef int* none_t; introduces type alias for pointer to integer.
  • typedef int non_helper::*none_t; introduces type alias for pointer to integer member of non_helper class.
Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
1

none_t is a pointer to member variable with type int of none_helper.

struct none_helper
{
  int x1;
  int x2;
};

int none_helper::* ptm = &none_helper::x1;
^^^^^^^^^^^^^^^^^^
     none_t
Kirill V. Lyadvinsky
  • 97,037
  • 24
  • 136
  • 212