CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Simple (?) template question.

  1. #1
    Join Date
    Jul 2007
    Posts
    2

    Simple (?) template question.

    I would like to know why the following does not compile:

    Code:
    struct A {
      template <unsigned N> void foo() {}
    };
    template <typename T> struct B {
      void foo() {
        T t;
        t.foo<0>(); // error: parse error before ';' token
      }
    };
     int main() {
      B< A> b;
      b.foo();
      return 0;
    }
    It's like it does not know the prototype of the templated foo.
    I would like to avoid any declaration of A in B.
    This example seems a bit daft but I have reason to decalre things like this.

    I am using gcc 3.3.2

    Thanks for any answer!

  2. #2
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    Re: Simple (?) template question.

    Not sure but try the following:

    Code:
    template <typename T> struct B {
      void foo() {
        T t;
        t.template foo<0>(); 
      }
    };
    EDIT: However your original code works on VC++ 8.0
    Last edited by miteshpandey; July 23rd, 2007 at 10:17 AM.
    If there is no love sun won't shine

  3. #3
    Join Date
    Jul 2007
    Posts
    2

    Re: Simple (?) template question.

    That solved all my issues!

    Many thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)