繁体   English   中英

在模板参数中将const unsigned int转换为unsigned int

[英]Converting const unsigned int to unsigned int in template parameter

使用以下代码:

#include <iostream>

template< class T, unsigned int NVectorDimension = 3 >
class Vector
{
};

template< unsigned int TDimension >
int RunTest( void )
{
  const unsigned int VectorDimension = 4;
  typedef Vector< int, VectorDimension >     VectorPixelType;
}

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

  return 0;
}

我得到:

In function ‘int RunTest()’:
12:40: error: could not convert template argument ‘VectorDimension’ to ‘unsigned int’
error: invalid type in declaration before ‘;’ token

任何想法这有什么问题吗?

大卫

gcc确实存在错误。 现在已修复: http : //gcc.gnu.org/bugzilla/show_bug.cgi?id=48657

正如评论中所说,这应该很好。 否则,您可以负担得起稍微更改class Vector声明吗? 可以尝试一下。

template< class T, const unsigned int NVectorDimension = 3 >
class Vector  //   ^^^^^  adding const here
{
};

如果这不起作用,那么可以尝试使用宏解决方法作为最后的选择。

int RunTest( void )
{
#define VectorDimension 4
  typedef Vector< int, VectorDimension >     VectorPixelType;
   // ...
#undef VectorDimension
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM