Redian新闻
>
请问关于overloading << (转载)
avatar
请问关于overloading << (转载)# JobHunting - 待字闺中
x*a
1
【 以下文字转载自 Programming 讨论区 】
发信人: xiaojiya (xiaojiya), 信区: Programming
标 题: 请问关于overloading <<
发信站: BBS 未名空间站 (Wed Feb 27 11:59:50 2013, 美东)
I am working on the example in accelerated C++.
I have overloaded operator+= , operator+ , and operator<<.>the following code does not work.
I got "invalid operands to binary expression('ostream'(aka 'basic_ostream<
char>') and 'myString') when compiling the code.
myString s1="hello";
myString s2="world";
std::cout<< s1+s2 <it worked in the following way.
myString s1="hello";
myString s2="world";
myString s=s1+s2;
std::cout<< s <what should I do to make the first one work?
Thanks a lot!
avatar
P*b
2
加个括号应该就可以了

【在 x******a 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 发信人: xiaojiya (xiaojiya), 信区: Programming
: 标 题: 请问关于overloading <<
: 发信站: BBS 未名空间站 (Wed Feb 27 11:59:50 2013, 美东)
: I am working on the example in accelerated C++.
: I have overloaded operator+= , operator+ , and operator<<.>: the following code does not work.
: I got "invalid operands to binary expression('ostream'(aka 'basic_ostream<
: char>') and 'myString') when compiling the code.
: myString s1="hello";

avatar
x*a
3
thanks, got the answer.

【在 P*******b 的大作中提到】
: 加个括号应该就可以了
avatar
l*8
4
应该是const的问题吧?

【在 x******a 的大作中提到】
: thanks, got the answer.
avatar
x*a
5
you are right!

【在 l*********8 的大作中提到】
: 应该是const的问题吧?
avatar
S*I
6
Do you know why const works fine? :) I put detailed answer on programming
board.

【在 x******a 的大作中提到】
: you are right!
avatar
x*a
7
I read it. the explanation is great! Thanks.

【在 S**I 的大作中提到】
: Do you know why const works fine? :) I put detailed answer on programming
: board.

avatar
d*g
8
学习了~
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。