Friending '>>' with own class

后端 未结 1 1562
不知归路
不知归路 2021-01-16 17:48

I have the following class, which I friended with cout and now I\'m trying to friend it with cin but I get an error... Could anyone help me, or tel

相关标签:
1条回答
  • 2021-01-16 18:48

    There is not enough code to answer your question. But from error I would say you, that your int RAngle::operator<(RAngle) is not defined as const method and you use it somewhere, where you have only const.

    Also, it's not very good practive to make operator< or other comparison operators return int, because this may lead to misunderstanding. Such operators should return bool.

    So, there sould be something like this bool RAngle::operator<(const RAngle& other) const { /*...*/ }. This topic is covered here and here.

    Update This code is completely strange. Why use pointers to int? Why make some data private? Constructor RAngle(int i,int j,int k) will not work as you suppose.

    0 讨论(0)
提交回复
热议问题