打印

重载问题

[复制链接]
772|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
txcy|  楼主 | 2012-4-17 18:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
// 函数调用
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;
    }
}

//重载函数
//函数1
template <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();
}
//函数2
template <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();
}
//函数3
template <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();
}
//函数4
template <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&)’有歧义

相关帖子

沙发
xsgy123| | 2012-4-17 21:29 | 只看该作者
只有按值传递,才不需要考虑const,如果传递的是指针或引用,有const和没有const,是不一样的

使用特权

评论回复
板凳
秋天落叶| | 2012-4-17 21:43 | 只看该作者
错误信息全贴出来吧

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

274

主题

2106

帖子

0

粉丝