Error compiling program with nested template classes
Dan May
danmay@securityprofiling.com
Tue Nov 18 22:16:00 GMT 2003
Hello,
I have been having a problem compiling a program that has a templated
structure inside of a templated structure. here is some code that
generates the compiler errors:
template<class T>
struct traits{
static const int i = 0;
};
template<int i>
struct outer
{
template<class T>
struct inner{
static void do_something(){
//perform an action
}
};
};
template<class T>
void func(T t){
outer< ::traits<T>::value>::inner<T>::do_something();
}
int main(int,char**){
func('c');
}
there error messages are as follows:
temp.cc: In function `void func(T) [with T = char]':
temp.cc:23: instantiated from here
temp.cc:19: error: type/value mismatch at argument 1 in template
parameter list
for `template<int i> struct outer'
temp.cc:19: error: expected a constant of type `int', got `char'
temp.cc:19: error: type/value mismatch at argument 1 in template
parameter list
for `template<int i> template<class T> struct outer<i>::inner'
temp.cc:19: error: expected a constant of type `int', got `char'
temp.cc:10: confused by earlier errors, bailing out
% gcc --version
gcc (GCC) 3.3.2
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I believe I am passing the correct template parameters. If anyone could
show me what I am doing wrong, or, if this is a bug, how to work around
it I would be grateful.
Thanks,
-Dan May
More information about the Gcc-help
mailing list