x******a 发帖数: 6336 | 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! |
P*******b 发帖数: 1001 | 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";
|
x******a 发帖数: 6336 | 3 thanks, got the answer.
【在 P*******b 的大作中提到】 : 加个括号应该就可以了
|
l*********8 发帖数: 4642 | 4 应该是const的问题吧?
【在 x******a 的大作中提到】 : thanks, got the answer.
|
x******a 发帖数: 6336 | 5 you are right!
【在 l*********8 的大作中提到】 : 应该是const的问题吧?
|
S**I 发帖数: 15689 | 6 Do you know why const works fine? :) I put detailed answer on programming
board.
【在 x******a 的大作中提到】 : you are right!
|
x******a 发帖数: 6336 | 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.
|
d*********g 发帖数: 154 | |