By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Problem when using template as the base class?

P: n/a
Hi,

I have the following program. It also includes the non-template
equivalent class, which works fine. If you uncomment the comments, you
will see compiler error. Do you know what is wrong?

BTW, I use g++-3.4.

Thanks,
Peng

#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"].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_argumentsarg();
plot_arguments1 arg1();
}

Sep 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

Pe*******@gmail.com wrote:
Hi,

I have the following program. It also includes the non-template
equivalent class, which works fine. If you uncomment the comments, you
will see compiler error. Do you know what is wrong?
What is the erorr you get?

Sep 22 '06 #2

P: n/a

Noah Roberts wrote:
Pe*******@gmail.com wrote:
Hi,

I have the following program. It also includes the non-template
equivalent class, which works fine. If you uncomment the comments, you
will see compiler error. Do you know what is wrong?

What is the erorr you get?
main_1mod_bim_plot.cc: In member function `int
plot_arguments<T>::boundary_pad() const':
main_1mod_bim_plot.cc:16: error: expected primary-expression before
"int"
main_1mod_bim_plot.cc:16: error: expected `;' before "int"
main_1mod_bim_plot.cc:16: error: expected primary-expression before
"int"
main_1mod_bim_plot.cc:16: error: expected `;' before "int"
main_1mod_bim_plot.cc: At global scope:
main_1mod_bim_plot.cc:29: warning: unused parameter 'argc'
main_1mod_bim_plot.cc:29: warning: unused parameter 'argv'
make: *** [main_1mod_bim_plot-g.o] Error 1

Sep 22 '06 #3

P: n/a
Pe*******@gmail.com wrote:
Noah Roberts wrote:
>Pe*******@gmail.com wrote:
>>Hi,

I have the following program. It also includes the non-template
equivalent class, which works fine. If you uncomment the comments, you
will see compiler error. Do you know what is wrong?
What is the erorr you get?

main_1mod_bim_plot.cc: In member function `int
plot_arguments<T>::boundary_pad() const':
main_1mod_bim_plot.cc:16: error: expected primary-expression before
"int"
main_1mod_bim_plot.cc:16: error: expected `;' before "int"
main_1mod_bim_plot.cc:16: error: expected primary-expression before
"int"
main_1mod_bim_plot.cc:16: error: expected `;' before "int"
main_1mod_bim_plot.cc: At global scope:
main_1mod_bim_plot.cc:29: warning: unused parameter 'argc'
main_1mod_bim_plot.cc:29: warning: unused parameter 'argv'
make: *** [main_1mod_bim_plot-g.o] Error 1
All I have is the GNU compiler, but I've seen this sort of error
before. I think it is an error in the compiler, but maybe one
of the language lawyers can tell us differently.

template <typename T>
int plot_arguments<T>::boundary_pad() const
{
// This compiles
boost::program_options::variables_map &tmp = &T::_vm;
return tmp["boundary_pad"].as<int>();

// This didn't
// return T::_vm["boundary_pad"].as<int>();
}
Sep 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.