Bug 20578 - Problem with templates
Summary: Problem with templates
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-21 15:29 UTC by Martin Hansen
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Hansen 2005-03-21 15:29:36 UTC
The following C++ code does not compile, which I believe it should (It 
compiles on gcc 1.1.1 and Microsoft's VS.NET):

--------Code start--------
template <class T>
class A {
protected:
  int a;
};

template <class T>
class B: public A<T> {
public:
  void f() { a = 5; }
};
--------Code end--------
I get the following error:
test.cpp: In member function `void B<T>::f()':
test.cpp:10: error: `a' undeclared (first use this function)
test.cpp:10: error: (Each undeclared identifier is reported only once for each 
function it appears in.)
asterix:components/mde> /pack/gcc/3.4.3/bin/g++ test.cpptest.cpp: In member 
function `void B<T>::f()':
test.cpp:10: error: `a' undeclared (first use this function)
test.cpp:10: error: (Each undeclared identifier is reported only once for each 
function it appears in.)
Comment 1 Andrew Pinski 2005-03-21 15:32:47 UTC
No this should not compile.  a is not dependent so it needs to be looked up at the point of the 
definition and not instaination.

Read the 3.4.x release notes to figure out how to fix your code.
Comment 2 Martin Hansen 2005-03-21 15:49:03 UTC
Subject: RE:  Problem with templates

Thank you for an extreemly quick response. My code is now compiling:-)


Med venlig hilsen / kind regards

Martin Hansen 
Lead Architect, Products

Systematic Software Engineering A/S
Søren Frichs Vej 39, DK-8000  Aarhus C
Tel.: +45 8943 2123
Fax: +45 8943 2020
Web: www.systematic.dk  


-----Original Message-----
From: pinskia at gcc dot gnu dot org [mailto:gcc-bugzilla@gcc.gnu.org] 
Sent: 21. marts 2005 16:33
To: Martin Hansen
Subject: [Bug c++/20578] Problem with templates


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-21 15:32 ------- No this should not compile.  a is not dependent so it needs to be looked up at the point of the definition and not instaination.

Read the 3.4.x release notes to figure out how to fix your code.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20578

------- You are receiving this mail because: ------- You reported the bug, or are watching the reporter.