I wanted to specify two very, very similar classes without having to write them out twice. However, when I specify member functions of one of the two possible cases, the compiler complains that the type I'm referring to is incomplete. What am I missing in this method? (stripped down)
Code:
template<class unary_func, bool Kd_weighted = false>
class sum : public func2d
{
public:
void operator()(grid::size_type x, grid::size_type y, grid::base_type & g, grid::data_type Kd = 1.0);
private:
grid::data_type s;
unary_func f;
};
template<class unary_func>
void sum<unary_func,false>::operator()(grid::size_type x, grid::size_type y, grid::base_type & g, grid::data_type Kd)
{
s += f( g(x,y) );
}
template<class unary_func>
void sum<unary_func,true>::operator()(grid::size_type x, grid::size_type y, grid::base_type & g, grid::data_type Kd)
{
s += Kd * f( g(x,y) );
}
Code:
error: invalid use of incomplete type ‘class functions::sum<unary_func, false>’|
error: declaration of ‘class functions::sum<unary_func, false>’|
error: invalid use of incomplete type ‘class functions::sum<unary_func, true>’|
error: declaration of ‘class functions::sum<unary_func, true>’|
Thanks.
*edit* Of course the classes are incomplete, but won't they be written at compile time, since I'm using them? Does the 'bool' not limit us to only two possibilities for a given unary_func?