2014-10-10 37 views
0

如何解決此編譯錯誤?彙編日誌表示調用者和候選人完全一樣,但是有超負荷和模糊性? 代碼:爲什麼在通過列表中作爲參數時出現歧義?

Ctrl.h 
namespace CvRcgCtrllr { 
    bool AssignPidsTo(const list<unsigned int> & pids, CvRcg & rcg); 
    bool RemovePidsFrom(const list<unsigned int> & pids, CvRcg & rcg); 
}; 

Ctrl.cpp 
using namespace CvRcgCtrllr; 
     30 bool AssignPidsTo(const list<unsigned int> & pids, Rcg & rcg) 
     31 {  
     44  return true; 
     45 } 
     46 
     47 bool RemovePidsFrom(const list<unsigned int> & pids, Rcg & rcg) 
     48 { 
     49  
     50  //Rcg default_rcg = GetNewRcg("default"); 
     51  //bool res = AssignPidsTo(pids, default_rcg); 
     52  return res; 
     53 } 

<!-- --> 

CvRcgCtrllr.cpp: In function ‘bool RemovePidsFrom(const std::list<unsigned int, std::allocator<unsigned int> >&, Rcg&)’: 
CvRcgCtrllr.cpp:51: error: call of overloaded ‘AssignPidsTo(const std::list<unsigned int, std::allocator<unsigned int> >&, Rcg&)’ is ambiguous 
CvRcgCtrllr.cpp:30: note: candidates are: bool AssignPidsTo(const std::list<unsigned int, std::allocator<unsigned int> >&, Rcg&) 
CvRcgCtrllr.h:20: note:     bool CvRcgCtrllr::AssignPidsTo(const std::list<unsigned int, std::allocator<unsigned int> >&, Rcg&) 
+1

我懷疑你沒有顯示足夠的代碼來推理你的錯誤。編譯器消息表明有''AssignPidsTo'函數,然後*另一個*'AssignPidsTo'函數作爲'CvRcgCtrllr'類中的成員。 – 5gon12eder 2014-10-10 23:34:58

+0

CvRcgCtrllr是一個名稱空間,AssignPidsTo是該名稱空間內的一個函數。在將AssignPidsTo更改爲CvRcgCtrllr :: AssignPidsTo後,它表示CvRcgCtrllr :: AssignPidsTo未定義。 – JackChen255 2014-10-10 23:46:33

+1

你應該顯示更多的代碼。嘗試製作可以現在複製的最短代碼樣本。 – ApplePie 2014-10-10 23:48:41

回答

1

你不能只是做

using namespace CvRcgCtrllr; 

,然後指定成員沒有範圍RESO定義命名空間成員運營商。它不工作,因爲你認爲它的工作原理。在您的代碼中,您在CvRcgCtrllr內聲明瞭一對函數,然後在全局名稱空間中額外定義了一對完全獨立的函數。這是在重載解析期間造成模糊的原因。

爲了定義你的函數從CvRcgCtrllr命名空間.cpp文件,你必須要麼重新命名空間

namespace CvRcgCtrllr 
{ 
    bool AssignPidsTo(const list<unsigned int> & pids, Rcg & rcg) 
    { 
    // Whatever 
    } 
} 

或使用的功能限定名

bool CvRcgCtrllr::AssignPidsTo(const list<unsigned int> & pids, Rcg & rcg) 
{ 
    // Whatever 
} 

有沒有辦法避免要麼這個或那個。 using namespace CvRcgCtrllr;不會幫你在這裏。

+0

謝謝。解決這個問題。 – JackChen255 2014-10-11 14:45:29

1

更換

using namespace CvRcgCtrllr; 

通過

namespace CvRcgCtrllr 
{ 
    // Your code of the file 
} 
相關問題