Hi,
I'm working through Stroustrup's Programming book (2nd ed.), and in Chapter 13 he has a derived struct (Open_polyline) that makes direct use of its base class (Shape) constructors' (which are declared to be protected) with:
1 2 3 4
|
struct Open_polyline : Shape {
using Shape::Shape;
...
}
|
OK, I get it. However, Shape has two constructors, namely:
1 2
|
Shape();
Shape(initializer_list<Point> lst);
|
and when I try to compile the code it fails for the 2nd constructor at run time with:
Graph.h:207:15: error: ‘Graph_lib::Open_polyline::Open_polyline(std::initializer_list<Graph_lib::Point>)’ is protected
using Shape::Shape;
^
graphics_examples/open_poly.cpp:14:5: error: within this context
};
However, if I get rid of that "using" statement and instead give the Open_polyline struct explicit calls to the base class constructors, i.e.:
1 2 3 4 5
|
struct Open_polyline : Shape {
Open_polyline() {};
Open_polyline(initializer_list<Point> lst) : Shape(lst) {};
...
};
|
it now all works. The base class constructors are still declared protected. Can anyone shed some light while the first method (with the "using" statement) fails, whereas the second works.
It's interesting to note that Stroustrup expects the first method to work. I've tested under both G++ and clang++ with identical results.
TIA
dmc