I have multiple classes that deal with some geometrical shape.
class Quad {
};
class Line {
};
Then, I have some classes that work on these shapes.
template< class Shape >
class Shape_Worker {
virtual
double
work(
Shape_Info< Shape >,
Other_Class_That_Depends_On< Shape > ) = 0;
}
class Shape_Worker_Quad : public Shape_Worker< Quad > {
double
work(
Shape_Info< Quad >,
Other_Class_That_Depends_On< Quad > ) {
// do something.
}
};
My class shape info stores some coordinate information. A line has a single coordinate, a quadrilateral has two coordinates, and inherits from the line.
template< class Shape >
class Shape_Info {
};
template<>
class Shape_Info< Line > {
protected:
double _r;
};
template<>
class Shape_Info< Quad > : public Shape_Info< Line > {
public:
Shape_Info< Quad >::Shape_Info(
const Shape_Info< Line > & abscissa_1,
const Shape_Info< Line > & abscissa_2 )
: Shape_Info< Line >( abscissa_1 )
, _s( abscissa_2._r )
{
}
protected:
double _s;
};
When I compile this code, I get the following error in the Shape_Info< Quad > copy constructor:
double Shape_Info< Line >::_r is protected.
What am I doing wrong? Shape_Info< Quad > is derived from Shape_Info< Line >, so I do not understand why it does not inherit the _r variable. Did I overlook something? Or does it have to do with my template specialization?
I'm using GCC 4.8.2.
Any feedback is appreciated, thank you!