未在c ++模板参数中使用constexpr

问题描述 投票:0回答:1

我正在使用类型为itk::Image<OutputPixelType, Dimension>的变量,其中“ itk”来自图像处理库ITK。

以下代码编译:

constexpr unsigned int Dimension = 3;
using PixelType = float; 
using MyImageType = itk::Image<PixelType, Dimension>;

但是现在我需要将“维度”定义为通过函数计算得出的值。

unsigned int Dimension = get_dimension(...);

我的编译器给出一个错误:

error: non-type template argument is not a constant expression
  using MyImageType = itk::Image<PixelType, Dimension>;
                                            ^~~~~~~~~

我该如何解决此问题?我希望将“维度”用作从函数计算得出的值。

c++ constexpr itk
1个回答
0
投票

您的get_dimension函数应为constexpr,如果是这种情况,则可以具有以下内容:

constexpr unsigned int Dimension = get_dimension(...);
© www.soinside.com 2019 - 2024. All rights reserved.