Auto foo (...) & # 8594; decltype (this) Is there a workaround?

I have the following class and try to declare a member function that will return a pointer to this type, but the following code

template<class Key, int b> class b_plus_tree_inner_node {
  auto split() -> decltype(this) {}
};

gives me such an error

misuse of 'this at the top level

Can I do it differently, now I'm talking about the existence of a typedef, but is this possible with decltype?

Edition:

I want to do this:

b_plus_tree_inner_node<Key, b>* split() {...}
+3
source share
2 answers

If you want the member function to declare it inside the class:

template<class Key, int b> class b_plus_tree_inner_node {
   b_plus_tree_inner_node* split(){}
   // also valid:
   //b_plus_tree_inner_node<Key, b>* split(){}
};

If you need a non-member function , make it a template:

template<class Key, int b>
b_plus_tree_inner_node<Key, b>* split(){}

The standard allows you to write auto split() -> decltype(this) {}, but GCC 4.6 does not yet support it (GCC 4.7 trunk).

+5

, :

template<class Key, int b> 
class b_plus_tree_inner_node 
{        
     b_plus_tree_inner_node<Key, b> split() 
     { 
          return /*...*/;
     }
};
0

All Articles