Error compiling program with nested template classes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux