This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

re: Help on class templates + friendship




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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]