This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Nested-template member function does not compile
- To: gcc-bugs at gnu dot org, bug-gcc at gnu dot org
- Subject: Nested-template member function does not compile
- From: "Alaeddin A. Aydiner" <aydiner at empc22 dot ece dot uiuc dot edu>
- Date: Wed, 13 Sep 2000 09:20:28 -0500
Hello,
In order to save you from having to read my actual code, I have hastily
written the small program below that compiles _unless_ MAYBEABUG is
defined.
[~/tmp][4034] >gcc -DMAYBEABUG try3.C
try3.C: In method `S<double,C>::S(C<double> &, N<double> &)':
try3.C:60: instantiated from here
try3.C:50: `CT' is not a template
try3.C:50: no matching function for call to `N<double>::f (C<double> &)'
In the above, CT is a nested template. When MAYBEABUG is not defined, a
regular template is employed instead, which compiles perfectly. Is the
nested case not allowed by the standard? Have I made a silly mistake? Or
is this an actual bug?
Thanks a lot.
--------------------------------------------------------------------------------
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)
Linux empc22.ece.uiuc.edu 2.2.16 #1 Thu Jun 8 23:57:46 CDT 2000 i686 unknown
--------------------------------------------------------------------------------
template<class T>
class N {
private:
T* c_;
unsigned short dim;
public:
N(const unsigned short& dim) : dim(dim) {
c_ = new T[dim];
}
#ifdef MAYBEABUG // does not compile
template<template<class> class CT>
void f(CT<T>& c) {
#else // compiles
template<class CT>
void f(CT& c) {
#endif
for (int i = 0; i < dim; i++)
c_[i] = c[i];
}
};
template<class T>
class C {
private:
T* c;
unsigned short dim;
public:
C(const unsigned short& dim) : dim(dim) {
c = new T[dim];
for (int i = 0; i < dim; i++) c[i] = 0;
};
inline const T& operator[](const unsigned short& dim) const {
return c[dim];
}
};
template<class T, template<class> class CT>
class S {
private:
CT<T>& c;
N<T>& node;
public:
S(CT<T>& c, N<T>& node) : c(c),
node(node) {
#ifdef MAYBEABUG // does not compile
node.template f<CT>(c);
#else // compiles
node.template f< CT<T> >(c);
#endif
}
};
int main(int argc, char** argv) {
C<double> c(3);
N<double> n(3);
S<double, C> sth(c, n);
}
--
#################################################################
Alaeddin Ahmet AYDINER 372A CCEM Everitt Laboratory MC 702
Office Tel: 217 333 4121 Electrical & Computer Eng. Dept. UIUC
#################################################################