2

Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?

#include <iostream>
using namespace std;

template <class T>
class Test
{
    union obj
    {
        union obj* next;
        int num;
    };

    static const int SZ=3;
    static obj* volatile list[SZ];
};

template <class T>
Test<T>::obj* volatile
Test<T>::list[SZ]=
{
    0, 0, 0
};

int main()
{
    return 0;
}

With g++, the error I get is:

18|error: expected constructor, destructor, or type conversion before '*' token
Community
  • 1
  • 1
prehistoricpenguin
  • 3,842
  • 1
  • 21
  • 34

1 Answers1

3

Add the keyword typename before Test<T>::obj* in the definition of the member.

Cosyn
  • 2,797
  • 21
  • 22
  • 1
    @Potatoswatter I think after the Test::list the names inside Test are in scope. Consider: `class A { class B {}; void c(B); }; void A::c(B) {}` – bames53 Apr 08 '12 at 04:34
  • @bames: You're actually right (sorry if you read my earlier comment). [Case in point](http://ideone.com/C0ALx). – Xeo Apr 08 '12 at 04:53
  • @bames53 bah, I deleted my comment about `SZ` needing qualification before looking it up in the standard. §9.4.2 [class.static.data] says "The initializer expression in the definition of a static data member is in the scope of its class (3.3.7)" but doesn't say anything about the declarator itself. Neither do I see anything under 8.4.2 [dcl.array]. So I think this might be a GCC bug. – Potatoswatter Apr 08 '12 at 10:13
  • @bames53: http://stackoverflow.com/questions/10062156/scope-of-evaluation-of-array-bound-of-static-data-member – Potatoswatter Apr 08 '12 at 10:39