读书人

关于重载歧义的有关问题

发布时间: 2012-05-05 17:21:10 作者: rapoo

关于重载歧义的问题
先看代码

C/C++ code
// 函数调用void Migrate::process(const DSReferenceID& id,const TapeName& oldtape){    bool ok;    Transaction(this,&Migrate::exists,id,oldtape,ok);    if(!ok)    {        Log::info() << oldtape << " does not exist in " << id << endl;        return;    }}//重载函数//函数1template <class Caller,class Arg1,class Arg2,class Arg3>inline void Transaction(Caller* caller,void (Caller::*proc)(Arg1&,Arg2&,Arg3&),Arg1& arg1,Arg2& arg2,Arg3& arg3){    TransactorM3<Caller,Arg1&,Arg2&,Arg3&>(*caller,proc,arg1,arg2,arg3).update();}//函数2template <class Caller,class Arg1,class Arg2,class Arg3>inline void Transaction(Caller* caller,void (Caller::*proc)(Arg1&,const Arg2&,Arg3&),Arg1& arg1,const Arg2& arg2,Arg3& arg3){    TransactorM3<Caller,Arg1&,const Arg2&,Arg3&>(*caller,proc,arg1,arg2,arg3).update();}//函数3template <class Caller,class Arg1,class Arg2,class Arg3>inline void Transaction(Caller* caller,void (Caller::*proc)(const Arg1&,Arg2&,Arg3&),const Arg1& arg1,Arg2& arg2,Arg3& arg3){    TransactorM3<Caller,const Arg1&,Arg2&,Arg3&>(*caller,proc,arg1,arg2,arg3).update();}//函数4template <class Caller,class Arg1,class Arg2,class Arg3>inline void Transaction(Caller* caller,void (Caller::*proc)(const Arg1&,const Arg2&,Arg3&),const Arg1& arg1,const Arg2& arg2,Arg3& arg3){    TransactorM3<Caller,const Arg1&,const Arg2&,Arg3&>(*caller,proc,arg1,arg2,arg3).update();}


我认为应该调用“函数4”,但编译的时候报
调用重载的‘Transaction(Migrate* const, void (Migrate::*)(const DSReferenceID&, const TapeName&, bool&), const DSReferenceID&, const TapeName&, bool&)’有歧义

高手们指点一二,谢了先

[解决办法]
探讨

只有按值传递,才不需要考虑const,如果传递的是指针或引用,有const和没有const,是不一样的。

[解决办法]
某些gcc可以编译。你的想编译通过的话估计只能显示给出参数类型来调用相应的版本了。

读书人网 >C++

热点推荐