Topic: Teaching C++


Author: "Stuart Golodetz" <sgolodetz@dial.pipex.com>
Date: Thu, 7 Jun 2001 18:40:13 GMT
Raw View
Well this is a 100% guess but wouldn't it cause a compile-time error if you
tried to then call the function from anywhere else in the program except
that function where you've declared it, except of course unless the function
was declared above the different function in its file...? Don't know whether
that would be useful or not really, didn't know you could do that before...
:o)

Stuart.

"Pavel Kuznetsov" <decraft@no.spam.bigfoot.com> wrote in message
news:9eoikr$g3g$1@taliesin.netcom.net.uk...
> Well, I suppose I'd be blamed, but it seems that
> /relative/ novices never stop misinterpret
> statements like below (took one from GotW#75):
>
> deque<string> coll3( istream_iterator<string>( cin ),
>                      istream_iterator<string>() );
>
> they always think that that is declares
>
> a variable named coll3 of type deque<string>
>    that is initialized with pair of iterators
>
> and not
>
> a function named coll3
>    that returns a deque<string> by value
>    and takes two parameters:
>       an istream_iterator<string> with a formal
>          parameter name of cin,
>       and a function with no formal parameter name
>          that returns an istream_iterator<string>
>          and takes no parameters.
>
> I'd say that many experienced programmers are
> being trapped here too.
>
> Does anybody knows how this problem could be eliminated?
> What is a profit of being able to declare
> the function inside other function?
>
> --
> Pavel Kuznetsov
> mailto:decraft@no.spam.bigfoot.com
> remove "no.spam." from e-mail address
>
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
>


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Thu, 7 Jun 2001 19:34:08 GMT
Raw View
In article <3b1fb599$0$15028$cc9e4d1f@news.dial.pipex.com>, Stuart
Golodetz <sgolodetz@dial.pipex.com> writes
>Well this is a 100% guess but wouldn't it cause a compile-time error if you
>tried to then call the function from anywhere else in the program except
>that function where you've declared it, except of course unless the function
>was declared above the different function in its file...? Don't know whether
>that would be useful or not really, didn't know you could do that before...
>:o)

Declaring a function lexically (note that, it is just a point of
declaration and the result is exported to the enclosing namespace scope)
inside another one is a common C idiom and was intended to limit the
visibility of a declaration.



Francis Glassborow      ACCU
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Pavel Kuznetsov" <decraft@no.spam.bigfoot.com>
Date: Sat, 26 May 2001 18:18:42 GMT
Raw View
Well, I suppose I'd be blamed, but it seems that
/relative/ novices never stop misinterpret
statements like below (took one from GotW#75):

deque<string> coll3( istream_iterator<string>( cin ),
                     istream_iterator<string>() );

they always think that that is declares

a variable named coll3 of type deque<string>
   that is initialized with pair of iterators

and not

a function named coll3
   that returns a deque<string> by value
   and takes two parameters:
      an istream_iterator<string> with a formal
         parameter name of cin,
      and a function with no formal parameter name
         that returns an istream_iterator<string>
         and takes no parameters.

I'd say that many experienced programmers are
being trapped here too.

Does anybody knows how this problem could be eliminated?
What is a profit of being able to declare
the function inside other function?

--
Pavel Kuznetsov
mailto:decraft@no.spam.bigfoot.com
remove "no.spam." from e-mail address


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]