0

I do have 2 simple classes in an Arduino Project.:

The classes were put in Point.h and Line.h files.

#include "Arduino.h"
#ifndef Point_h
#define Point_h

class Point{

    public:
        Point(int x);
        int getPunkt();
        void setPunkt(int x);

    private:
        int _x;
};

/////////////////////////////////
Point::Point(int x){
    _x = x;
}

int Point::getPunkt(){
    return _x;
}

void Point::setPunkt(int x){
    _x = x;
}
#endif

And:

#include "Point.h"
#ifndef Line_h
#define Line_h

class Line{

public:
    Line(Point p1, Point p2);

private:
    Point _p1;
    Point _p2;
};

Line::Line(Point p1, Point p2){
    _p1 = p1;
    _p2 = p2;
}

#endif

The constructor of Line gives me:

Multiple markers at this line - candidates are: - no matching function for call to 'Point::Point()'

What am I doing wrong? This is just a simple example.

Thank you

Dennis
  • 33
  • 6

1 Answers1

0

Use member initializer lists from now on. _p1 and _p2 have to be default constructed first (if you omit the member initializer list):

Line::Line(Point p1, Point p2) : _p1(), _p2() { ... }

to do the assignments later in the constructor's body. (Point does not have default constructor generated, because you've provided your own.)

You have to do this:

Line::Line(Point p1, Point p2) : _p1(p1), _p2(p2) {} // copy-initialize

(Do the same for Point::Point.)

LogicStuff
  • 19,397
  • 6
  • 54
  • 74
  • thank you very much. I didnt knew about this concept. Its completly new to me. But I will erad you Link. Thank you very much. This cost me a night. :-) – Dennis Jan 23 '16 at 08:49
  • You're welcome, but rather read the duplicate post first. – LogicStuff Jan 23 '16 at 08:50
  • Yeah I googled it on this site but didnt found the answer. But sorry for double posted question. – Dennis Jan 23 '16 at 08:56