Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > copy an istringstream

Reply
Thread Tools

copy an istringstream

 
 
Sharad Kala
Guest
Posts: n/a
 
      07-08-2004

"Alex Vinokur" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> "Sharad Kala" <(E-Mail Removed)> wrote in message

news:(E-Mail Removed)...

>
> But iss is not of istream_iterator<string> type; iss is of istringstream

type.

So? You think this won't compile?

float f;
void foo (int (f)); // ==> void foo (int f);

-Sharad


 
Reply With Quote
 
 
 
 
tom_usenet
Guest
Posts: n/a
 
      07-08-2004
On Thu, 8 Jul 2004 14:09:27 +0300, "Alex Vinokur"
<(E-Mail Removed)> wrote:

>
>"Sharad Kala" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>[snip]
>>
>> void foo( int d);
>> void foo (int (d)); // same as above; parens around d are ignored

>
>d is of int type
>
>>
>> With this knowledge, in vector<string> vec( istream_iterator<string>(iss),
>> istream_iterator<string>() );
>> the first parameter is of type istream_iterator<string>. The parentheses
>> around iss are superfluous and are ignored.

>[snip]
>
>But iss is not of istream_iterator<string> type; iss is of istringstream type.


Function declaration scope iss hides the prior one. This is perfectly
legal:

double d;
int f(int(d)); //function declaration, parameter named d.

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
 
Reply With Quote
 
 
 
 
Alex Vinokur
Guest
Posts: n/a
 
      07-08-2004

"Sharad Kala" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>
> "Alex Vinokur" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > "Sharad Kala" <(E-Mail Removed)> wrote in message

> news:(E-Mail Removed)...
>
> >
> > But iss is not of istream_iterator<string> type; iss is of istringstream

> type.
>
> So? You think this won't compile?
>
> float f;
> void foo (int (f)); // ==> void foo (int f);
>
> -Sharad
>
>


OK

Now is some problem with second parameter in foo2().

------ foo.cpp ------
void foo1 (int (i), int) {}
void foo2 (int (i), int()) {}
int main()
{
foo1 (10, 20); // Line#5
foo2 (30, 40); // Line#6
return 0;
}
---------------------

------ Compilation ------
$ g++ foo.cpp
foo.cpp: In function `int main()':
foo.cpp:6: error: invalid conversion from `int' to `int (*)()'
-------------------------


--
Alex Vinokur
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn




 
Reply With Quote
 
Sharad Kala
Guest
Posts: n/a
 
      07-09-2004

"Alex Vinokur" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> "Sharad Kala" <(E-Mail Removed)> wrote in message

news:(E-Mail Removed)...
> >
> > "Alex Vinokur" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > >
> > > "Sharad Kala" <(E-Mail Removed)> wrote in message

> > news:(E-Mail Removed)...
> >
> > >
> > > But iss is not of istream_iterator<string> type; iss is of

istringstream
> > type.
> >
> > So? You think this won't compile?
> >
> > float f;
> > void foo (int (f)); // ==> void foo (int f);
> >
> > -Sharad
> >
> >

>
> OK
>
> Now is some problem with second parameter in foo2().
>
> ------ foo.cpp ------
> void foo1 (int (i), int) {}



> void foo2 (int (i), int()) {}


This declares a function, foo2, whose return type is void. It takes two
parameters -
- The first parameter is names, its type is an int
- The second parameter has NO NAME. It's type is pointer to function taking
nothing and returning int as parameter.

Probably what you are missing is that parentheses around a parameter name
are ignored (as is in the case in our first parameter), but parentheses
standing by themselves (as is in our second parameter), indicate the
existence of a parameter list. They indicate the presence of a parameter
that is
itself a pointer to a function.

> int main()
> {
> foo1 (10, 20); // Line#5
> foo2 (30, 40); // Line#6
> return 0;
> }
> ---------------------
>
> ------ Compilation ------
> $ g++ foo.cpp
> foo.cpp: In function `int main()':
> foo.cpp:6: error: invalid conversion from `int' to `int (*)()'


The compiler error message should also give you the answer!

Hope that clears it.

-Sharad


 
Reply With Quote
 
Alex Vinokur
Guest
Posts: n/a
 
      07-09-2004

"Sharad Kala" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>
> "Alex Vinokur" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...

[snip]
> >
> > Now is some problem with second parameter in foo2().
> >
> > ------ foo.cpp ------
> > void foo1 (int (i), int) {}

>
>
> > void foo2 (int (i), int()) {}

>
> This declares a function, foo2, whose return type is void. It takes two
> parameters -
> - The first parameter is names, its type is an int
> - The second parameter has NO NAME. It's type is pointer to function taking
> nothing and returning int as parameter.
>
> Probably what you are missing is that parentheses around a parameter name
> are ignored (as is in the case in our first parameter), but parentheses
> standing by themselves (as is in our second parameter), indicate the
> existence of a parameter list. They indicate the presence of a parameter
> that is
> itself a pointer to a function.
>
> > int main()
> > {
> > foo1 (10, 20); // Line#5
> > foo2 (30, 40); // Line#6
> > return 0;
> > }
> > ---------------------
> >
> > ------ Compilation ------
> > $ g++ foo.cpp
> > foo.cpp: In function `int main()':
> > foo.cpp:6: error: invalid conversion from `int' to `int (*)()'

>
> The compiler error message should also give you the answer!
>
> Hope that clears it.
>
> -Sharad
>
>


Thanks.

Unfortunately C++ doesn't require void in function declaration.
It seems that void foo2 (int (i), int(void)) is more intuitive declaration.


--
Alex Vinokur
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn







 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is Deep Copy, shallow copy and bitwises copy.? saxenavaibhav17@gmail.com C++ 26 09-01-2006 09:37 PM
Avoiding copy: char* -> istringstream mathieu C++ 7 07-24-2006 07:03 PM
is dict.copy() a deep copy or a shallow copy Alex Python 2 09-05-2005 07:01 AM
istringstream to bool Agent Mulder C++ 8 08-23-2003 11:55 PM
Allocating istringstream objects Samuele Armondi C++ 1 07-11-2003 10:22 PM



Advertisments