由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ syntax question
相关主题
C++ class cross reference problem最近在用clj干活。顺便看了看macro 倒吸一口冷气。
template questionclass D:public B;
哪位能推荐一本python的书C++ Template Question
template 疑问recursive template?
An object of A automatically converted to an object of B.C++ memcpy declaration use restrict keyword?
What is wrong in this array declaration.请各位帮我看看这个最简单的Stored Procedure
一道面试怪题C++. (转载)address of an array
int *a [] 和int (*a)[] 一样吗pointer to function
相关话题的讨论汇总
话题: istreambuf话题: iterator话题: char话题: std话题: scontent
进入Programming版参与讨论
1 (共1页)
L*******s
发帖数: 63
1
Might be a stupid question...:
Why
std::string sContent((std::istreambuf_iterator(fi)),
std::istreambuf_iterator());
doesn't work, but
std::string sContent(std::istreambuf_iterator(fi),
std::istreambuf_iterator());
works? Thanks a lot!
t****t
发帖数: 6806
2
http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.2

【在 L*******s 的大作中提到】
: Might be a stupid question...:
: Why
: std::string sContent((std::istreambuf_iterator(fi)),
: std::istreambuf_iterator());
: doesn't work, but
: std::string sContent(std::istreambuf_iterator(fi),
: std::istreambuf_iterator());
: works? Thanks a lot!

P********e
发帖数: 2610
3
what do you mean by first doesn't work?
It is a valid statement.

【在 L*******s 的大作中提到】
: Might be a stupid question...:
: Why
: std::string sContent((std::istreambuf_iterator(fi)),
: std::istreambuf_iterator());
: doesn't work, but
: std::string sContent(std::istreambuf_iterator(fi),
: std::istreambuf_iterator());
: works? Thanks a lot!

P********e
发帖数: 2610
4
man, they are different.

【在 t****t 的大作中提到】
: http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.2
t****t
发帖数: 6806
5
for c++ opinion, just keep it to yourself.

【在 P********e 的大作中提到】
: man, they are different.
t****t
发帖数: 6806
6
ok, let me explain a bit. this is easy to get wrong.
i believe your original intention is to declare a string object sContent,
and initialize it with 2 iterators. that is fine. however, just as
int b;
declare an integer object b, while
int b();
declares a function called b, returning int, taking no parameters.
your 2nd statement (i will omit decorations)
string a(istreambuf_iterator(fi), istreambuf_iterator());
declares a function called a, returning string, taking 2 parameters: first
should be istreambuf_iterator, second should be a function pointer
returning istreambuf_iterator and taking no parameter.
1st statement with the extra () will prevent compiler from recognizing it as
function declaration, so it does what you want. if it doesn't work, there
must be something else wrong.

【在 L*******s 的大作中提到】
: Might be a stupid question...:
: Why
: std::string sContent((std::istreambuf_iterator(fi)),
: std::istreambuf_iterator());
: doesn't work, but
: std::string sContent(std::istreambuf_iterator(fi),
: std::istreambuf_iterator());
: works? Thanks a lot!

L*******s
发帖数: 63
7
Sorry, I meant the 1st one works, but the 2nd one doesn't.
(it did turn out to a stupid question...)

【在 P********e 的大作中提到】
: what do you mean by first doesn't work?
: It is a valid statement.

L*******s
发帖数: 63
8
Thanks a lot!

sContent,
first

【在 t****t 的大作中提到】
: ok, let me explain a bit. this is easy to get wrong.
: i believe your original intention is to declare a string object sContent,
: and initialize it with 2 iterators. that is fine. however, just as
: int b;
: declare an integer object b, while
: int b();
: declares a function called b, returning int, taking no parameters.
: your 2nd statement (i will omit decorations)
: string a(istreambuf_iterator(fi), istreambuf_iterator());
: declares a function called a, returning string, taking 2 parameters: first

c**b
发帖数: 2999
9
第一个参数太长,有时候compiler对太长的一串东西会有误解,所以全部括起来,安全起
见.

【在 L*******s 的大作中提到】
: Might be a stupid question...:
: Why
: std::string sContent((std::istreambuf_iterator(fi)),
: std::istreambuf_iterator());
: doesn't work, but
: std::string sContent(std::istreambuf_iterator(fi),
: std::istreambuf_iterator());
: works? Thanks a lot!

t****t
发帖数: 6806
10
靠, 没听说过这种理由.

【在 c**b 的大作中提到】
: 第一个参数太长,有时候compiler对太长的一串东西会有误解,所以全部括起来,安全起
: 见.

t****t
发帖数: 6806
11
by the way, this is explained exactly in . Item 6, to be
precise. I lost the book when moving, pity.
i believe you can find E-version of the book online.

【在 L*******s 的大作中提到】
: Thanks a lot!
:
: sContent,
: first

1 (共1页)
进入Programming版参与讨论
相关主题
pointer to functionAn object of A automatically converted to an object of B.
[合集] 问个及其初级问题。c++What is wrong in this array declaration.
问个c++在不同函数里分配内存和释放内存的弱问题一道面试怪题C++. (转载)
const char *p, is it ok to change p[1] ?int *a [] 和int (*a)[] 一样吗
C++ class cross reference problem最近在用clj干活。顺便看了看macro 倒吸一口冷气。
template questionclass D:public B;
哪位能推荐一本python的书C++ Template Question
template 疑问recursive template?
相关话题的讨论汇总
话题: istreambuf话题: iterator话题: char话题: std话题: scontent