
if(dimension == 2){ typedef itk::Image<short,2> ImageType; typedef itk::Image<unsigned int,2> IntegralimageType; m_pApp->train<2,ImageType,IntegralimageType>();}else{ typedef itk::Image<short,3> ImageType; typedef itk::Image<unsigned int,3> IntegralimageType; m_pApp->train<3,IntegralimageType>();} 但我想这样做:
if (dimension == 2) DIMENSION = 2; else DIMENSION = 3; typedef itk::Image<short,DIMENSION> ImageType; typedef itk::Image<unsigned int,DIMENSION> IntegralimageType; m_pApp->train<DIMENSION,IntegralimageType>();
我无法做到这一点,因为c需要const变量用于模板实例化.
有没有这样的方法呢?
template<unsigned N>voID train(){ typedef itk::Image<short,N> ImageType; typedef itk::Image<unsigned int,N> IntegralimageType; m_pApp->train<N,IntegralimageType>();} 然后:
if (dimension == 2) train<2>();else train<3>();
请注意,此代码将实例化两个模板(将为它们生成代码),因为在编译时无法知道将使用哪个模板.
总结以上是内存溢出为你收集整理的C模板实例化取决于if子句全部内容,希望文章能够帮你解决C模板实例化取决于if子句所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)