overloading friend operator<< for template class

后端 未结 5 781
误落风尘
误落风尘 2020-11-22 01:34

I have read couple of the questions regarding my problem on StackOverflow.com now, and none of it seems to solve my problem. Or I maybe have done it wrong... The overloaded

5条回答
  •  失恋的感觉
    2020-11-22 02:03

    You can't declare a friend like that, you need to specify a different template type for it.

    template 
    friend ostream& operator<< (ostream & os, const D& rhs);
    

    note SclassT so that it doesn't shadow classT. When defining

    template 
    ostream& operator<< (ostream & os, const D& rhs)
    {
      // body..
    }
    

提交回复
热议问题