Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typedef type * type::* , what is it?

Tags:

c++

I have the following code:

  struct myType { myType * ptr; };
  typedef myType * myType ::* other_type;

What is the second line typedef'ining? Is that a member function that returns a myType pointer or something else?

like image 310
user3498783 Avatar asked Apr 15 '14 12:04

user3498783


1 Answers

That defines other_type as a pointer to a member of myType where said member is itself a pointer to myType. For example, you could use it this way:

other_type x = &myType::ptr;
myType mine;
mine.*x = &mine;

Why you would do that, I can't say.

like image 85
John Zwinck Avatar answered Sep 17 '22 22:09

John Zwinck