考虑下面的代码: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