1

I was trying to setup some default constructors, but keep running into the error:

newton.h:29:38: error: type ‘Newton’ is not a direct base of ‘Newton’

I can't grasp what I am doing wrong, I am using g++ with std=c++0x (c++11 compiler setting).

Newton.h:

#ifndef Newton_h
#define Newton_h

#include <armadillo>
#include "qr.h"

using namespace std;
using namespace arma;

class Newton {
 public:

  class Lambda {
  public:
    virtual double walkLambda(Newton newt) {};
  };

  class linearL : public Lambda {
  public:
    double walkLambda(Newton newt);
  };

  Newton(function<vec(vec)> f,
     vec xStart, vec dx,
     const double eps, function<mat(vec)> dfdx = 0, Lambda lambda = linearL());

  Newton(function<vec(vec)> f,
     vec xStart, vec dx,
     const double eps, Lambda lambda) : Newton(f, xStart, dx, eps, 0, lambda) {} // Line 29!

  vec getRoots();
  int getCalls();

 protected:
  int _n, _calls;
  vec _x, _dx, _y, _fx, _fy, _df;
  mat _j;
  function<vec(vec)> _f;
};
#endif

Thank you for your time. Best.

Theis
  • 53
  • 5
  • There's no way to call constructor from another constructor in C++. See this: http://stackoverflow.com/questions/308276/c-call-constructor-from-constructor – Nick Hill Jun 14 '13 at 19:26
  • Delegating constructors were not introduced until C++11. Make sure you are using a C++11 compiler that supports this feature and C++11 mode is enabled. – Captain Obvlious Jun 14 '13 at 19:34
  • 2
    @NikolayKhil _"There's no way to call constructor from another constructor in C++"_ ... You should read the accepted solution to the question you linked to. At the very bottom it mentions delegating constructors, includes a link to relevant information and provides an example. – Captain Obvlious Jun 14 '13 at 19:38
  • @CaptainObvlious yeah, thanks for that. I forgot that C++11 introduces such a cool feature. – Nick Hill Jun 14 '13 at 19:42
  • As I mentioned i use g++ with std=c++0x, which is the c++11 setting for the g++ compiler. – Theis Jun 14 '13 at 19:59
  • 1
    @user1320157. Well, delegating constructors are available in gcc starting from version 4.7. And the right compiler option is -std=c++11 (std=c++0x is for older features). – Nick Hill Jun 14 '13 at 20:13
  • @NikolayKhil -std=c++0x is not for older features, but for older versions of GCC. In versions that support -std=c++11, that and -std=c++0x have the same effect. –  Jun 14 '13 at 20:26
  • Thank you guys, checked it, and the server I am working on only runs 4.6.3. – Theis Jun 16 '13 at 16:03

0 Answers0