由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ Q22: ostream
相关主题
【c++里override输出<<总出错】问一道kth smallest element的题目
请问关于overloading << (转载)新鲜G面筋(2)
问个c++题一个新鲜twitter面经
One C++ question问一道题(2)
C++ 一问?请教ebay 的面试题一道
发发面经 攒人品 C++的Why should i include .cpp instead of .h
Google Japan电面about namespace
amazon第三轮电面为什么在overloading中,friend <<不能读取private值呢?
相关话题的讨论汇总
话题: base话题: ostream话题: derived话题: std话题: operator
进入JobHunting版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
#include
using namespace std;
class Base {
protected:
virtual void output(std::ostream& os) { os << "Base\n"; }
};
class Derived : private Base {
friend std::ostream& operator<<(std::ostream&, Derived&);
};
std::ostream& operator<<(std::ostream& os, Derived& d) {
d.output(os);
}
int main() {
Base b; Derived d;
std::cout << b << d;
}
For which one of the following reasons is the code above INVALID?
a) Base::output is defined for Base, but operator<< is defined for Derived.
b)
P*******b
发帖数: 1001
2
c

【在 c**********e 的大作中提到】
: #include
: using namespace std;
: class Base {
: protected:
: virtual void output(std::ostream& os) { os << "Base\n"; }
: };
: class Derived : private Base {
: friend std::ostream& operator<<(std::ostream&, Derived&);
: };
: std::ostream& operator<<(std::ostream& os, Derived& d) {

P*******b
发帖数: 1001
3
c)


【在 c**********e 的大作中提到】
: #include
: using namespace std;
: class Base {
: protected:
: virtual void output(std::ostream& os) { os << "Base\n"; }
: };
: class Derived : private Base {
: friend std::ostream& operator<<(std::ostream&, Derived&);
: };
: std::ostream& operator<<(std::ostream& os, Derived& d) {

M********5
发帖数: 715
4
我也觉得是c
l*******o
发帖数: 791
5
C
c**********e
发帖数: 2007
6
You guys are all right.
c) There is no operator<< defined for Base.
This is the correct answer. The code will fail to compile because you try
to output a Base object, and there is no corresponding operator<<.
1 (共1页)
进入JobHunting版参与讨论
相关主题
为什么在overloading中,friend <<不能读取private值呢?C++ 一问?
c++小问题发发面经 攒人品 C++的
please help debug this codeGoogle Japan电面
再问两个C++问题amazon第三轮电面
【c++里override输出<<总出错】问一道kth smallest element的题目
请问关于overloading << (转载)新鲜G面筋(2)
问个c++题一个新鲜twitter面经
One C++ question问一道题(2)
相关话题的讨论汇总
话题: base话题: ostream话题: derived话题: std话题: operator