Why can't I declare template type aliases inside functions?

Why can't I declare a template alias inside a function?

#include <vector>

int main(){

    //type alias deceleration:
    template <typename T>
    using type = std::vector<T>;

    //type instantiation:
    type<int> t;

}

error: template declaration cannot be displayed in the scope area

Why are we forced to place these ads outside the block area?

#include <vector>

//type alias deceleration:
template <typename T>
using type = std::vector<T>;

int main(){

    //type instantiation:
    type<int> t;
}
+4
source share
1 answer

The standard says so.

From the C ++ 11 standard (shock):

14 Pattern

2 . . [. , --, -- --. , simple-template-id, (14.5.5). -end note]

+4

Source: https://habr.com/ru/post/1621303/


All Articles