簡體   English   中英

調用函數時發生C ++錯誤

[英]C++ Error in calling the function

我具有以下形式的函數定義(在較大的代碼內):

class Abc{
 public:
 bool func(const std::string& text,::DE::d type,unsigned a,unsigned& b);
 };

DE是以下形式的類:

class DE
{
   public:
   enum d{U,L};

};

現在,我以以下形式調用該函數:

string s;
unsigned st=0;
int idj;
cout<<"\n Enter the value of string:";
cin>>s;
Abc abc;
abc.func(s,DE::U, 0,  idj); 
cout<<idj;

abc.func(s,DE::U, 0, idj);調用func函數時abc.func(s,DE::U, 0, idj); 我收到以下提到的錯誤。 有人可以幫助您找到並糾正錯誤嗎?

我得到的錯誤是:

   error: no matching function for call to ‘Abc::func(std::string&, DE::U, unsigned int&, int&)’

您應該閱讀有關訪問說明符的信息

class Abc{
 bool func(const std::string& text,::DE::d type,unsigned a,unsigned& b);
};

Abc::func()是私有的,因此不能從外部調用或引用。 DE enum相同。

另外,您不能傳遞int ,其中需要引用unsigned int

idjint類型的; 它應該是unsigned int才能作為參數b傳遞。

最后一個參數類型是對unsigned的引用。 您正在嘗試將引用傳遞給int ,這是另一種類型。

修復該問題后,您將發現無法調用該函數,因為該函數是私有的。 同樣,您也不能訪問DE::U因為它也是私有的。 更新 :這是指在添加public訪問說明之前,最初發布的問題。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM