Typedef declaration syntax
A few days ago I looked at the boost sources and found an interesting typedef .
There is 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 have not seen such syntax before and cannot explain the meaning of it.
This typedef introduces the name "none_t" as a pointer to an int in the boost :: detail namespace.
What is syntax?
What's the difference between " typedef int none_helper :: * none_t " and, for example, " typedef int * none_t "?
a source to share
The syntax is for a pointer to a member - here it's typedefs none_t
as a pointer to a data member int
none_helper
.
The syntax can be used for example. in the following 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 for more details.
a source to share