1

I usually use the following line to declare/init a unique_ptr for a class named T:

unique_ptr<T> tPtr(new T());

However, I've also seen the following.

unique_ptr<class T> tPtr(new T());

I've tested both and there seems to be no difference when using the two. So, is there any advantage in putting the class keyword? For example, does it optimize anything? Or is there more to it?

ShadowRanger
  • 108,619
  • 9
  • 124
  • 184
A. Mashreghi
  • 1,465
  • 2
  • 15
  • 28
  • 2
    It's an elaborated type specifier. See [here](https://stackoverflow.com/questions/28007165/class-keyword-in-variable-definition-in-c), [here](https://stackoverflow.com/questions/35959438/what-is-the-class-keyword-before-a-function-argument) or [here](https://stackoverflow.com/questions/29754917/class-keyword-on-return-type-c). I guess we don't have a dupe that discusses elaborated type specifiers when used as template arguments (but that's also hard to search for without getting unrelated results). Edit: Better dupe is https://stackoverflow.com/questions/50436381/c-template-type-specification – Max Langhof Dec 11 '19 at 18:20

0 Answers0