🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++
Article #303

Cannot use templates with nested classes in G++ 2.7.0

#303
From: Stefan Ratschan
Date: Wed, 23 Aug 1995 13:49
38 lines
1320 bytes
When I try to compile the following code with G++ 2.7.0, I get an error
message:

---
template <class T> class X {
 public:
  class A {
  };
  X<T>::A GetAttr(void);
 private:
  X::A attr;
};

template <class T> void X<T>::A X<T>::GetAttr(void) {
  return attr;
};
---
test.cc:10: parse error before `<'

It seems that G++ can refer to nested classes only inside of the envelope
class, because the following works:

template <class T> class X {
 public:
  class A {
  };
  X<T>::A GetAttr(void) { return attr; };
 private:
  X::A attr;
};

However I would like to define the function out of the class declaration.

Is this a problem of C++ or of the G++ compiler?
Is there any different solution that works?
Or did I just use the wrong syntax?

Stefan Ratschan
Technical Details
Message-ID: <41fblh$f17@alijku06.edvz.uni-linz.ac.at>
Path: arc1-ca.pugleaf.net!newsfeed.ACO.net!alijku06!news

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newsfeed.ACO.net!alijku06!news
From: Stefan Ratschan <sratscha>
Newsgroups: gnu.g++,comp.lang.c++
Subject: Cannot use templates with nested classes in G++ 2.7.0
Date: 23 Aug 1995 13:49:37 GMT
Organization: Johannes Kepler University Linz
Message-ID: <41fblh$f17@alijku06.edvz.uni-linz.ac.at>
NNTP-Posting-Host: edelweiss.risc.uni-linz.ac.at
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 1.1N (X11; I; IRIX 5.3 IP7)
X-URL: news:gnu.g++