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:

Newton-Raphson Method in C++

The Newton Raphson Method is an open method used to find the roots of a function. It employs the technique of linear approximation and invol...