www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - question about accessing static member

↑ ↓ ← "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
↑ ↓ → 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