3

In the code:

typedef
template< typename T>
boost::variant<T::* int, T::* string, T::* double, T::* bool>
   any_member;

What does the T::* mean/do?

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
Matt
  • 1,928
  • 24
  • 44
  • 6
    See [c-pointer-to-class-data-member](http://stackoverflow.com/questions/670734/c-pointer-to-class-data-member) – Jarod42 Dec 04 '15 at 15:38
  • 2
    Huh, what makes you guys think that this is valid C++ code? – cpplearner Dec 04 '15 at 16:01
  • @cpplearner: You're right, must be a transcription error in the OP. Should be `int T::*` etc. – AndyG Dec 04 '15 at 19:00
  • 1
    [Here's an example that might use it](http://coliru.stacked-crooked.com/a/a3dfb673216483ff). Note that I in no way endorse actually doing this; the pattern is an attempt at being generic, and there's better ways to do what I linked to. – AndyG Dec 04 '15 at 19:23
  • @cpplearner I found that example on this blog: http://blog.asymptotic.co.uk/2011/02/c-pointer-template-parameters-are-weird/ I haven't read this comprehensively, but that code that's at the top through me off right away. – Matt Dec 06 '15 at 17:58
  • @Matt That code is not even close to correct AFAICS. – cpplearner Dec 07 '15 at 09:59

1 Answers1

3

T::* is a pointer to a member of T. The int is the type of that member.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • 1
    Maybe I am too nitpicky, but you have used the word "type" both for `T` and `int`. To avoid confusion I would rephrase it as "`T::* int` is a pointer to a member of *class* T; this member is of type `int`". The downvote isn't mine though (and if this is the reason I really think it's excessive). – Fabio says Reinstate Monica Dec 04 '15 at 15:47
  • The downvote was mine. The question is marked duplicate, and the close flags were already there before this answer was created. On top of that, there were already comments on the OP both answering the question and linking to the dup. This answer didn't have a reason to exist in my opinion. It's not a critique against the content of it, however. – AndyG Dec 04 '15 at 15:50
  • 2
    @AndyG Well the close flags were placed while I was posting the answer. In my opinion it not exactly a dupe of the linked to question as the syntax is different. It is your vote so you can do what you want with it but I am leaving the answer here. – NathanOliver Dec 04 '15 at 15:52