Thread: Templated templates...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    725

    Templated templates...

    ...my temple hurts.

    I'm writing (potentially) template-heavy code, and I've encountered this problem which fortunately can be isolated:

    Code:
    #include <vector>
    template <class a_type>
    class a_class
    {
        public:
            void foo()
            {
                std::vector <a_type>::iterator i;
            }
    };
    Now when I try to compile this code in GCC it gives
    Code:
    In member function 'void a_class<a_type>::foo()': expected ';' before "i"
    I'm thinking the reason is in the way the STL implements its iterators... you need a well-defined class for them. But I'm not sure.

    EDIT: Okay, after fiddling around I found that using typename would resolve the error. (And finally got a chance to learn what the keyword did.) I'm still open to explanations...
    Last edited by jafet; 09-03-2006 at 01:36 AM.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Templates from DLL or static library problem
    By mikahell in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2008, 01:49 AM
  2. Questions about Templates
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2005, 12:22 AM
  3. templates and inheritance problem
    By kuhnmi in forum C++ Programming
    Replies: 4
    Last Post: 06-14-2004, 02:46 AM
  4. When and when not to use templates
    By *ClownPimp* in forum C++ Programming
    Replies: 7
    Last Post: 07-20-2003, 09:36 AM