[英]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
。
idj
是int
类型的; 它应该是unsigned int
才能作为参数b
传递。
最后一个参数类型是对unsigned
的引用。 您正在尝试将引用传递给int
,这是另一种类型。
修复该问题后,您将发现无法调用该函数,因为该函数是私有的。 同样,您也不能访问DE::U
因为它也是私有的。 ( 更新 :这是指在添加public
访问说明之前,最初发布的问题。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.