タイトルが示すように、decltype を使用してテンプレートの型を取得しようとしていました。私がこれを試した方法は次のとおりです。
template<typename T> class List
{
....
public:
typedef T type;
....
};
メイン.CPP
int main(int argc, char* argv[])
{
List<int> intl;
decltype(intl)::type t; // compiler doesnt try to access the decltype's members but reverts to global namespace (as if i had typed :: on a new line
}
私の印象では、decltype は文字通りに書いたかのように型を返しました (コードでは "int" とも呼ばれます)。そうではありませんか?
また、テンプレート クラスから型名 T を取得する他の方法はありますか?
前もって感謝します。
延長:
List<int> intl;
typedef decltype(intl) listtype;
listtype::type i;
私は unsigned int です...私は混乱しています
わかりました。1 で WOO 2 コンパイラ エラー :) unsigned int を宣言する for ループがありました (その後スコープ外になりましたが、何らかの理由で後で使用したときに unsigned int のままでした)