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 at ima dot udg dot es
- Subject: re: Help on class templates + friendship
- From: Benjamin Kosnik <bkoz at cygnus dot com>
- Date: Fri, 29 Oct 1999 10:02:06 -0700 (PDT)
- cc: gcc at gcc dot gnu dot org
Hey. Try this.
see 14.1 template parameters for more info (esp 13: scope)
-benjamin
--------------
// forward decl
template<typename TS, typename TV2> class B;
template<typename TV>
class C {
public:
// Actually referring to different params, need to use different names
template<typename TS, typename TV2> friend class B;
C(int j=0) : j_(j) {}
private:
int j_;
};
template<typename TS, typename TV2>
class B {
public:
B(int i=0) : i_(i) {}
B& operator+=(const B& rhs) { i_ += rhs.i_; return *this; }
B& operator+=(const C<TV2>& rhs) { i_ += rhs.j_; return *this; }
private:
int i_;
};
int main() {
B<int, float> foo;
C<float> bar;
foo += bar;
}