LoginSignup
3

More than 5 years have passed since last update.

alias templateが関数内で使えなかった話(alias declarationとalias templateは似て非なるものだった)

Last updated at Posted at 2014-09-08

以下のようにmain関数でalias declaration的なのりでalias templateを使おうとしたらうまく行かなかった。

int main(int argc, char const* argv[]) {


    template<typename T>
    using MyType = T;

    return 0;
}

でたコンパイルエラーは

a template declaration cannot appear at block scope

そこで規格(n3242)を読んでみたら14章のテンプレートのところに下記の記述があった。

A template-declaration can appear only as a namespace scope or class scope declaration.

ようするにテンプレートの宣言は名前空間のスコープあるいはクラスのスコープ内でしかできないというもの。
そしてAlias templatesは名前の通りテンプレート。
どおりでできないわけだ。

alias declarationとalias templateは似て非なるものだったんですね。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3