【问题标题】:cannot convert parameter 1 from 'VP<T>' to 'VP<T> &' , yet another VS bug无法将参数 1 从 'VP<T>' 转换为 'VP<T> &' ,又一个 VS 错误
【发布时间】:2012-09-04 15:59:18
【问题描述】:

以下代码在 gcc 中没有问题。在 VS 2010 express 中它失败了

------ 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 ==========

对于任何 Visual Studio 版本都一样,还是仅限于 vs 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);
   }

【问题讨论】:

  • @SethCarnegie 你在哪里测试的?
  • 我知道它并没有违反任何 C++ 规则,也确认一下,ideone.com/nDoVO
  • 谢谢,我只是想知道,我应该更新到 vs 2012 还是问题仍然存在?
  • 不,它在 VS 2012 中也被破坏了。
  • @SethCarnegie:- `它没有违反 C++ 的任何规则`,但它打破了 VS 的脊梁;)

标签: c++ visual-studio templates


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-04-14
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-13
    相关资源
    最近更新 更多