This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Help on class templates + friendship
- To: Frederic Perez <frederic at ima dot udg dot es>
- Subject: Re: Help on class templates + friendship
- From: patrick <patrick at mail dot boxsoft dot com>
- Date: Sat, 30 Oct 1999 11:35:27 -0700
- Cc: "gcc list (aka egcs)" <gcc at gcc dot gnu dot org>
- References: <3819AC08.69F8649C@ima.udg.es>
Try a patch similar to this:
(note: my source is different than yours since i had to re-type it.
Hence this patch will not work properly on your source. It
is meant only for demonstration purpose)
// begin
--- tf.cc-orig Sat Oct 30 11:28:09 1999
+++ tf.cc Sat Oct 30 11:28:44 1999
@@ -18,7 +18,7 @@
class C
{
public:
- template< typename TS, TV> friend class B; // gcc chokes here?
+ template< typename TS, typename TV> friend class B; // fixed now!
C( int j = 0 ) : j_(j) { };
private:
// end
This changed applied, the source compiles fine under:
% g++ -v
Reading specs from
/usr/local/egcs-1.1.2/lib/gcc-lib/i686-pc-linux-gnulibc1/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
* Frederic Perez (frederic@ima.udg.es) [991030 10:48]:
> Hello everyone,
>
> While porting a program to Linux using GCC (from SGI using MIPSpro)
> I'm having troubles trying to establish a friendship between
> two class templates, and I still don't know if this is due to
> a restriction on the GCC compiler or to a wrong use of notation.
>
> What follows is an over-simplified version of the code that fails
> to compile:
>
> --------------------
>
> template<typename TV> class C; // forward declaration
>
> template<typename TS, typename TV>
> class B {
> public:
> B(int i=0) : i_(i) {}
> B& operator+=(const B& rhs) { i_ += rhs.i_; return *this; }
> B& operator+=(const C<TV>& rhs) { i_ += rhs.j_; return *this; }
> private:
> int i_;
> };
>
> template<typename TV>
> class C {
> public:
> template<typename TS, TV> friend class B; //makes it crash using gcc-2.51.1
> C(int j=0) : j_(j) {}
> private:
> int j_;
> };
>
> int main() {
> B<int, float> foo;
> C<float> bar;
> foo += bar;
> }
patrick
--
two guys walk into a bar... one of them goes "ouch!"