I'm working by myself through Bjarne Stroustrup's principles of programming book and am having trouble with defining constructors. This question requires using an interface which is built from the FLTK graphics library; generally no worries there. We have to make a smileyface out of the circle class, which does not have a default constructor - the regular constructor takes in a (x,y) point and a radius. I wanted to be able to make some calculations/do other stuff - so tried to define the constructor for my smileyface outside of the class body. This doesn't work, and I keep getting an error (from visual studio) of "no default constructor exists for class "Graph_lib::Circle".
struct Smiley :public Circle {
Smiley(Point p, int rr);
void draw_lines() const;
void sc(Color c);
Circle l_eye;
Circle r_eye;
};
Smiley::Smiley(Point p, int rr) {
Circle(p, rr);
Circle l_eye(Point(p.x - 50, p.y - 50), rr / 8);
Circle r_eye(Point(p.x + 50, p.y - 50), rr / 8);
}
Basically, the above doesn't work. I think its trying to somehow create a default Circle for some reason, however cannot find the default function for it (as I haven't written one) and then throws the error. I've tried heaps of different combinations for this function but can't seem to get it to not try and fine a default. Note that if I get rid of the "Circle" type before l_eye and r_eye in the Smiley::Smiley - it still throws an error of "call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type".
However, if I just define it in the initialization list, it works fine.
struct Smiley :public Circle {
Smiley(Point p, int rr) : Circle(p, rr), l_eye(Point(p.x - 50, p.y - 50), rr/8), r_eye(Point(p.x + 50, p.y - 50), rr/8) {}
void draw_lines() const;
void sc(Color c);
Circle l_eye;
Circle r_eye;
};
Obviously, this is a pretty trivial example. However, I think it's important for me to get this as there will be lots of times in the future where I will need to actually do computation in an outside constructor function. If anyone could help explain what the problem is that would be great.