不能将参数1从'VP <t>'转换为'VP <t>&amp;' ,另一个VS bug </t> </t>

时间:2012-09-04 15:59:19

标签: c++ visual-studio templates

以下代码在gcc中没有问题。在VS 2010表示它没有给出

------ Build started: Project: helium, Configuration: Debug Win32 ------
  testvs.cpp
..\..\helium\src\legacy\testvs.cpp(21): error C2664: 'ulink' : cannot convert parameter 1 from 'VP<T>' to 'VP<T> &'
          with
          [
              T=F
          ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

对于任何视觉工作室版本都是一样的,还是仅限于2010年的问题? 如果删除第二个operator()定义,问题就会消失

template<typename T> struct S{
    void operator()(T&){}
    void operator()(){}
};



  template <typename T,typename G=typename T::GP,void (S<T>::*f)(T&) =&S<T>::operator() > struct VP{
 void fa(){}
 };


template<typename T> void ulink( VP<T >& v){}



  struct F{
    typedef int GP;
  };

   void f(){

     VP<F> vps;
     ulink(vps);
   }

1 个答案:

答案 0 :(得分:3)

感谢Seth Carnegie确认这是另一个VS未解决的错误。

可能的解决方法

1)包含在另一个结构中

template<typename L> struct Con{
     L& l;
     Con(L& pl):l(pl){}
};

template<typename T> void ulink(const Con<VP<T > >& v){
v.l.fa();
}

2)保持模板更通用

template<typename T> void gulink(T& v){
v.fa();
}