ciccio wrote:
> 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
Sorry, which one?
> 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?
They both can be failing.
>
> Thanks for the help
>
>
> [ testing]$ g++ -c car.cpp
To verify your code better, you need to make the compilation _strict_
and _conforming_. Here you're just letting GNU extensions loose.
> [ 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> &);
If youi need a particular instantiation of 'foo' to be the friend,
you need to give it the template arguments, I believe
friend void foo<T>(car<T>&, car<T>&);
Have you tried that?
> };
> #endif
> ============= car.cpp =============
> #include "car.hpp"
> template class car<int>;
> ===================================
So, have you actually tried inserting the entire 'car.hpp' into
'car.cpp' and then posting it here. It doesn't matter really that
you have two files, does it?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
|