VC2008 refuses to compile the following code, and I can't understand why.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: VC2008 refuses to compile the following code, and I can't understand why.

  1. #1
    Join Date
    Aug 2009
    Posts
    1

    VC2008 refuses to compile the following code, and I can't understand why.

    template<typename T> class A {
    template<typename U> class B;
    template<typename U> class C;
    template<typename U> class B {
    typedef C<U> D;
    D *c;
    T u;
    };
    template<typename U> class C { // It works fine if I change 'C' to 'D' here.
    typedef B<U> B;
    B *b;
    T v; //VC2008 complains about this line, that T is undefined.
    };
    };

    A<int> a;

  2. #2
    Join Date
    Nov 2003
    Posts
    1,793

    Re: VC2008 refuses to compile the following code, and I can't understand why.

    Use code tags, so the indentation isn't stripped off.
    Code:
    template<typename T> class A {
        typedef T AT;
    
        template<typename U> class B;
        template<typename U> class C;
    
        template<typename U> class B {
            typedef C<U> D;
            D *c;
            typename A::AT u;
        };
    
        template<typename U> class C { 
            typedef B<U> B;
            B *b;
            typename A::AT v;
        };
    };
    It's a bug. You can explicitly disambiguate things so the compiler doesn't confuse itself.

    gg

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center