考慮下面的代碼:C++模板初始化
template<typename T>
class MyContainer
{
typedef T value_type;
typedef unsigned int size_type;
...
};
如何應該使用SIZE_TYPE(如循環索引)初始化變量?
它應該是:
for(size_type currentIndex = size_type(0);currentIndex < bound;++currentIndex)
或
for(size_type currentIndex = static_cast<size_type>(0);currentIndex < bound;++currentIndex)
的問題的基本原理是產生代碼時型基礎SIZE_TYPE更改或添加到模板參數仍然可以工作。
謝謝...
增加了問題的基本原理。 – 2010-02-22 20:55:37