C
ciccio
Dear all, once again I stumbled upon the following puzzling problem.
When having the following two files (see below), the gnu compiler
compiles the file without a problem while the compiler complains about
the fact that the function foo (which is declared as a template) is not
a template! The problem itself vanishes when changing the name of the
function foo in the class bar into some other function name, lets say goo.
The problem apears to originate from the same function name which excist
in the parent class.
So my question is now, is this syntax correct, or is one of the
compilers failing?
Thanks for the help
[ testing]$ g++ -c car.cpp
[ testing]$ icpc -c car.cpp
vector.hpp(13): error: foo is not a template
friend void foo <> (car<T> &, car<T> &);
^
detected during instantiation of class "car<T> [with T=int]"
at line 2 of "car.cpp"
compilation aborted for vector.cpp (code 2)
======== car.hpp ========
#ifndef CAR_HPP
#define CAR_HPP
template<typename T> class bar {
public :
void foo(bar<T> &); // not working
// void goo(bar<T> &); THIS ONE WOULD WORK
};
template<typename T> class car;
template<typename T> void foo(car<T> &, car<T> &);
template<typename T> class car : public bar<T> {
friend void foo <> (car<T> &, car<T> &);
};
#endif
============= car.cpp =============
#include "car.hpp"
template class car<int>;
===================================
When having the following two files (see below), the gnu compiler
compiles the file without a problem while the compiler complains about
the fact that the function foo (which is declared as a template) is not
a template! The problem itself vanishes when changing the name of the
function foo in the class bar into some other function name, lets say goo.
The problem apears to originate from the same function name which excist
in the parent class.
So my question is now, is this syntax correct, or is one of the
compilers failing?
Thanks for the help
[ testing]$ g++ -c car.cpp
[ testing]$ icpc -c car.cpp
vector.hpp(13): error: foo is not a template
friend void foo <> (car<T> &, car<T> &);
^
detected during instantiation of class "car<T> [with T=int]"
at line 2 of "car.cpp"
compilation aborted for vector.cpp (code 2)
======== car.hpp ========
#ifndef CAR_HPP
#define CAR_HPP
template<typename T> class bar {
public :
void foo(bar<T> &); // not working
// void goo(bar<T> &); THIS ONE WOULD WORK
};
template<typename T> class car;
template<typename T> void foo(car<T> &, car<T> &);
template<typename T> class car : public bar<T> {
friend void foo <> (car<T> &, car<T> &);
};
#endif
============= car.cpp =============
#include "car.hpp"
template class car<int>;
===================================