H
hweekuan
Hi,
I got an error with gnu C++ but not with intel C++ (icc). The distilled
code is given below, a variable "T" is stored as a const T& in the base
class and when the derived class try to access it, the compiler gives
an error. Compile error with gnu C++ and version of C++ compiler is
also given below. I don't know if its compiler bug.
Any help and comments will be very much appreciated. Thank you.
----------------------------------------------------------------
#include <iostream>
#include <vector>
template<class T> class baseClass {
protected:
baseClass(const T& r)(r) { }
const T& p;
};
template<class T> struct derivedClass : public baseClass<T> {
derivedClass(const T& u) : baseClass<T>(u) { }
void f() { std::cout<<baseClass<T>:[0]<<std::endl; } // error here
};
typedef std::vector<double> V;
int main() {
V v(2,1);
derivedClass<V> dc1(v);
dc1.f();
}
------------------------------------------
// compile error
inheritance.cc: In member function `void derivedClass<T>::f() [with T =
V]':
inheritance.cc:27: instantiated from here
inheritance.cc:16: error: invalid types `const V&[int]' for array
subscript
// compiler specs
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1493)
I got an error with gnu C++ but not with intel C++ (icc). The distilled
code is given below, a variable "T" is stored as a const T& in the base
class and when the derived class try to access it, the compiler gives
an error. Compile error with gnu C++ and version of C++ compiler is
also given below. I don't know if its compiler bug.
Any help and comments will be very much appreciated. Thank you.
----------------------------------------------------------------
#include <iostream>
#include <vector>
template<class T> class baseClass {
protected:
baseClass(const T& r)(r) { }
const T& p;
};
template<class T> struct derivedClass : public baseClass<T> {
derivedClass(const T& u) : baseClass<T>(u) { }
void f() { std::cout<<baseClass<T>:[0]<<std::endl; } // error here
};
typedef std::vector<double> V;
int main() {
V v(2,1);
derivedClass<V> dc1(v);
dc1.f();
}
------------------------------------------
// compile error
inheritance.cc: In member function `void derivedClass<T>::f() [with T =
V]':
inheritance.cc:27: instantiated from here
inheritance.cc:16: error: invalid types `const V&[int]' for array
subscript
// compiler specs
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1493)