0

I have a function definition of the following form (within a large code):

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

Here DE is a class of the following form:

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

};

Now I am calling the function in the following form:

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;

Upon the call of the function func in abc.func(s,DE::U, 0, idj); I am getting the below mentioned error. Can someone be kind enough to help find and rectify the error.

The error that I am getting is:

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

3 Answers3

4

You should read about access specifiers.

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

Abc::func() is private, so cannot be called, or referenced, from outside. Same with enum in DE.

Plus, you cannot pass int, where reference to unsigned int is required.

Community
  • 1
  • 1
Griwes
  • 8,805
  • 2
  • 43
  • 70
2

idj is of type int; it should be unsigned int to be passed as parameter b.

ecatmur
  • 152,476
  • 27
  • 293
  • 366
2

The last parameter type is a reference to unsigned. You are trying to pass a reference to int, which is a different type.

Once you fix that, you'll find that you can't call the function because it is private; likewise, you can't access DE::U since that's also private. (UPDATE: this refers to the question as originally posted, before public access specifiers were added.)

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644