Problem when using template as the base class?
Peng Yu
pengyu.ut@gmail.com
Fri Sep 22 23:47:00 GMT 2006
> I have the following program. It also includes the non-template
> equivalent class, which works fine. If you uncomment the comments, you
> will see the compiler errors. The errors are also shown below. Do you
> know what is wrong? Is it a bug of the compiler?
>
> BTW, I use g++-3.4.
I corrected the error by adding template keyword. But I don't
understand why "template" keyword is need. Would you please help me?
#include <iostream>
#include <boost/program_options.hpp>
class base_arguments {
public:
base_arguments() {}
protected:
boost::program_options::variables_map _vm;
};
template <typename T>
class plot_arguments : public T {
public:
plot_arguments() {}
int boundary_pad() const {
return T::_vm["boundary_pad"].template as<int>();
}
};
class plot_arguments1 : public base_arguments {
public:
plot_arguments1(){}
int boundary_pad() const {
return base_arguments::_vm["boundary_pad"].as<int>();
}
};
int main(int argc, char *argv[])
{
plot_arguments<base_arguments> arg();
plot_arguments1 arg1();
}
More information about the Gcc-help
mailing list