[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
template subclass bug
From: |
Jon Wilkening |
Subject: |
template subclass bug |
Date: |
Sat, 16 Jul 2005 16:50:17 -0400 (EDT) |
dear g++ developers,
I have found the following bug when compiling under cygwin (g++ version
3.4.4 on a pentium 4 laptop) and under solaris (g++ version 3.4.3 on an
sunblade 2000). It works correctly in fedora core 2 on a pentium 4
laptop when compiled with g++ version 3.3.3, and on the sunblade 2000 when
compiled with Sun's native CC compiler.
Best regards,
Jon Wilkening
-----
the file subclass.cpp is included below. It should compile without
errors, but instead gives:
math1 ~ 81% g++ subclass.cpp
subclass.cpp: In member function `void B<T>::out()':
subclass.cpp:17: error: `x' undeclared (first use this function)
subclass.cpp:17: error: (Each undeclared identifier is reported only once
for each function it appears in.)
if I comment out line 17 and uncomment line 18, it works as expected, but
it shouldn't be necessary to qualify x with the superclass name.
------
#include <iostream>
#include <stdio.h>
using namespace std;
template<class T>
class A {
public:
T x;
A(T x_) : x(x_) { }
};
template<class T>
class B : public A<T> {
public:
B(T x_) : A<T>(x_) { }
void out() { cout << x << endl; }
// void out() { cout << A<T>::x << endl; }
};
int main() {
B<int> i(5);
B<double> w(5.3);
i.out();
w.out();
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- template subclass bug,
Jon Wilkening <=