无法将参数 1 从"VP"<T>转换为"VP<T> &",这是另一个 VS 错误

cannot convert parameter 1 from 'VP<T>' to 'VP<T> &' , yet another VS bug

本文关键字:lt gt VP 另一个 错误 VS 转换 参数      更新时间:2023-10-16

以下代码在gcc中没有问题。在VS 2010 express中,它未能给出

------ Build started: Project: helium, Configuration: Debug Win32 ------
  testvs.cpp
....heliumsrclegacytestvs.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年的问题?如果删除的第二个运算符()定义,问题就会消失

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);
   }

感谢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();
}