You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//[Where and why do I have to put the “template” and “typename” keywords?](https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords)
11
+
//[Qualified name lookup](https://en.cppreference.com/w/cpp/language/qualified_lookup)
12
+
13
+
template<typename T>
14
+
classAnimal{
15
+
public:
16
+
usingPtr = std::shared_ptr< Animal< T > >;
17
+
};
18
+
19
+
template<typename T>
20
+
voidf(){
21
+
Animal<T> a;
22
+
23
+
//error: need ‘typename’ before ‘Animal<T>::Ptr’ because ‘Animal<T>’ is a dependent scope
24
+
//error: expected ‘;’ before ‘ap’
25
+
//Animal<T>::Ptr ap;
26
+
27
+
//correct
28
+
typename Animal<T>::Ptr ap;
29
+
}
30
+
31
+
intmain(){
32
+
//ok
33
+
Animal<int> a;
34
+
//when template argument is concrete, we don't need to add "typename"
0 commit comments