由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请问关于overloading << (转载)
相关主题
问个c++题Why I can't compile this function successfully
发发面经 攒人品 C++的C++ 一问?
One C++ question请教一个c的概念题
C++ Q42: (C22)面试又挂了!难过死
one C++ question问个简单coding问题
C++ Q83: 这个const_cast什么意思?C++ Q22: ostream
请教C/C++小问一个C++问题:default parameter and overriding/inheritanc
请教ebay 的面试题一道问一道无聊的bloomberg电面题
相关话题的讨论汇总
话题: mystring话题: s1话题: s2话题: std话题: operator
进入JobHunting版参与讨论
1 (共1页)
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
8
学习了~
1 (共1页)
进入JobHunting版参与讨论
相关主题
问一道无聊的bloomberg电面题one C++ question
问一道kth smallest element的题目C++ Q83: 这个const_cast什么意思?
给大家看几道C 小程序请教C/C++小
【c++里override输出<<总出错】请教ebay 的面试题一道
问个c++题Why I can't compile this function successfully
发发面经 攒人品 C++的C++ 一问?
One C++ question请教一个c的概念题
C++ Q42: (C22)面试又挂了!难过死
相关话题的讨论汇总
话题: mystring话题: s1话题: s2话题: std话题: operator