Home How to declare pointers/references to template class member types?
Reply: 0

How to declare pointers/references to template class member types?

user783
1#
user783 Published in April 27, 2018, 6:52 am

I hope the title is not too far off. Consider the following piece of code:

template<class C>
struct Wrapper {
  using type = C;
};

int main()
{
  Wrapper<int>::type *a;
  Wrapper<int*>::type b;
  int i;
  Wrapper<int>::type &c = i;
  Wrapper<int&>::type d = i;
}

Here, * and & can either go into the template argument or can be attached to the variable name. While I think both ways of declaring have the same effect, this is just my question:

Are the different ways of declaring pointers/references equivalent or are there situations in which one of them is preferred over the other for whatever reasons (e.g. safer, compiles faster, better style, ...)?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.44148 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO