我'不知道是否有可能訪問的給定爲在以後的模板參數前面的模板參數模板參數列表,像這樣的類型的類型定義:訪問模板參數列表中以前模板參數的typedefs?
#include <iostream>
template<typename V>
struct TypeHolder {
typedef V value_type;
};
template<typename T, T::value_type v>
struct ValueHolder {
const static typename T::value_type value = v;
};
int main() {
typedef TypeHolder<int> IntTypeHolder;
typedef ValueHolder<IntTypeHolder,5> Five;
std::cout << Five::value << std::endl;
return 0;
}
當我編譯上面的例子中,我得到以下錯誤:
[email protected]:~$ g++ -o cpptest test.cpp
test.cpp:8:25: error: 'T::value_type' is not a type
這是由於錯誤的語法或什麼,我想在C++做的只是不可能++?
你的第一個問題是結構定義末尾缺少分號。我修復了這個問題,並更新了更相關的錯誤。如果我做錯了,請告訴我。 –