www.digitalmars.com         C & C++   DMDScript  

c++ - question about accessing static member

reply "Szabolcs Horvát" <szhorvat yahoo.co.uk> writes:
Could someone help with the following question:
If the following example compiles without errors, why doesn't it work when I
make the member B::a static? (It works with Borland C++)


This one compiles without error:

template<class T> struct A { T t; };

class B {
private:
 struct C { int i; };
 A<C> a;
public:
 B() { a.t.i = 0; }
}


Error: member 'B::C' of class 'B' is not accessible

template<class T> struct A { T t; };

class B {
private:
 struct C { int i; };
 static A<C> a;    // member a made static
public:
 B() { a.t.i = 0; }
}

A<B::C> B::a;


Sorry for my poor English.
Sep 09 2004
parent Daniel James <daniel calamity.org.uk> writes:
Szabolcs Horvát wrote:
 Error: member 'B::C' of class 'B' is not accessible
 
 template<class T> struct A { T t; };
 
 class B {
 private:
  struct C { int i; };
  static A<C> a;    // member a made static
 public:
  B() { a.t.i = 0; }
 }
 
 A<B::C> B::a;
Unless I've missed something, you've found a bug. This works on g++ and intel linux, provided you add the required semi-colon after your class definition.
 Sorry for my poor English.
No need to apologise, it looks fine to me. Daniel
Sep 09 2004