D
derek
(Message also posted to comp.std.c++)
I have just been experimenting with g++ 3.4 and code that I thought was
compliant has raised compiler problems. Basically, if we have the
following code:
#include <iostream>
using std::cout;
template<typename T>
class A {
public:
T f() {return T();};
};
template<typename T>
class B : public A<T> {
public:
void g() {cout << f() << "\n";};
};
int main()
{
B<int> b;
b.g();
};
I would have expected the call to f() in g() to be OK. However, it isn't
for g++ 3.4:
checker.cc: In member function `void B<T>::g()':
checker.cc:14: error: there are no arguments to `f' that depend on a
template parameter, so a declaration of `f' must be available
checker.cc:14: error: (if you use `-fpermissive', G++ will accept your
code, but allowing the use of an undeclared name is deprecated)
Replacing f() with A<T>::f() will fix it. But is it a valid error, or is
g++ 3.4 wrong?
Thanks for any insights anyone can offer on this.
Derek
I have just been experimenting with g++ 3.4 and code that I thought was
compliant has raised compiler problems. Basically, if we have the
following code:
#include <iostream>
using std::cout;
template<typename T>
class A {
public:
T f() {return T();};
};
template<typename T>
class B : public A<T> {
public:
void g() {cout << f() << "\n";};
};
int main()
{
B<int> b;
b.g();
};
I would have expected the call to f() in g() to be OK. However, it isn't
for g++ 3.4:
checker.cc: In member function `void B<T>::g()':
checker.cc:14: error: there are no arguments to `f' that depend on a
template parameter, so a declaration of `f' must be available
checker.cc:14: error: (if you use `-fpermissive', G++ will accept your
code, but allowing the use of an undeclared name is deprecated)
Replacing f() with A<T>::f() will fix it. But is it a valid error, or is
g++ 3.4 wrong?
Thanks for any insights anyone can offer on this.
Derek