Re: conflict between friend function and inherited class function
ciccio wrote:
<snip>
To verify your code better, you need to make the compilation _strict_
and _conforming_. Here you're just letting GNU extensions loose.
What do you mean with gnu extensions? Could you elaborate a bit on
this?
Not sure what to tell you. GNU C++ is a slightly different language
than standard C++. It's full of extensions, some of which are bugs
in the compiler or in the compiler creators' understanding of the
Standard. You need to disable those. See man page to find out what
command-line switches to use.
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?
Yep, it gives the same error. And the above rule is given in faq-lite
also. When I remove the <> from the friend declaration, i.e.
friend void foo(car <T> &, car<T> &);
The intel compiler gives a warning saying that I might need to include
the <> .
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?
Sorry, you are right there, here is the one file example
=== START CAR.CPP ======
template<typename T> class bar {
public :
void foo(bar<T> &);
};
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 <T> (car<T> &, car<T> &);
};
car<int> a;
===== END CAR.CPP =====
Again the same question remains, why does foo from the class bar
conflicts with the friend definition of the template function foo in
the class car?
The code you posted here compiles without a problem with Comeau online.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask