3

When I call getCount function in the below code, QT 4.7.3 complier giving the error. Build Error

pasing 'cont Person' as 'this' argument of 'int Person::getCount(const QString&) discards qualifiers

 bool Person::IsEligible(const QString& name)
 {
      int count = 0;
      count = getCount(name);
 }

 int Person::getCount(const QString& name)
 {
  int k =0
  return k;
 }

1 Answer 1

4

The error isn't a problem with passing string arguments, it's that you've got a const person, e.g.:

const Person p1;
Person p2;
p1.IsEligible("whatever"); //Error   
p2.IsEligible("whatever"); //Fine because p2 isn't const

If IsEligible is meant to be callable on const Persons then you can say:

bool Person::IsEligible(const QString& name) const
 {
      int count = 0;
      count = getCount(name);
 }

(and change the corresponding declaration that you've not shown too obviously), but I'm not 100% sure that's what you intended to do.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks awoodland, delcarations are int getCount(const QString& name). bool IsEligible(const QString& name) const which is a public slots. I will change as you mentioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.