Friday

Qt C++: Solution for “error: only constructors take member initializers” and “warning: no return statement in function returning non-void [-Wreturn-type]”

Qt C++: Solution for “error: only constructors take member initializers” and “warning: no return statement in function returning non-void [-Wreturn-type]”

C++ Code with Error and Warning messages:

class ClassName
{
private:
  QString s;
  double d;
public:
  ClassKName(QString s="noName", double d=0.0) : s(s), d(d)
  {
  }
};

Solution:

The constructor name is different from the class name.
Rename the constructor name ClassKName to be the same with ClassName without the extra letter ‘K’.
 

No comments:

If a hater attacked your age and not the goodness of you

Whether young or old, I've always been known what endures. I've known the very idea of people that were all created equal and deserv...