Topic: Temporary object generation


Author: artfulbobATmindspringDOTcom@nntp6.atl.mindspring.net (Albert)
Date: 1999/09/06
Raw View
I hope the title is correct. Can anyone tell me why the
following won't work?

int function(int x)
{
  x = 10;
}

int main()
{
  function(int);
}

Umm, you get the idea. If int were a class with a default constructor,
I don't see why it wouldn't be allowed.

--

Albert (TheCheeseMan) (Baud Bard)
http://home.earthlink.net/~thecheezeman
http://conceptual.virtualave.net
ICQ: 14617788

"I don't know why I did it,
I don't know why I enjoyed it,
and I don't know why I'll do it again."
- Bart Simpson
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Stephan Kaemper <Stephan.Kaemper@t-online.de>
Date: 1999/09/06
Raw View
Albert wrote:
> I hope the title is correct. Can anyone tell me why the
> following won't work?
>
> int function(int x)
> {
>   x = 10;

A (non void) function should return a value!
How about

    return x;   ??

> }
>
> int main()
> {
>   function(int);
> }

Shouldn't this be

    function(2);         // ???

> I don't see why it wouldn't be allowed.

Because it's non standard, I suppose!?
Tell me if I'm wrong.

--
Stephan K   mper                      Mail: Stephan.Kaemper@t-online.de
Bremen / Germany
                                          |    |    |
                                         )_)  )_)  )_)
                                        )___))___))___)\
                                       )____)____)_____)\\
                                     _____|____|____|____\\\__
                            ---------\                   /---------
                               ^^^^^ ^^^^^^^^^^^^^^^^^^^^^
                                ^^^^      ^^^^     ^^^    ^^
                                     ^^^^      ^^^



[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: jpotter@falcon.lhup.edu (John Potter)
Date: 1999/09/07
Raw View
On 06 Sep 99 17:15:03 GMT,
artfulbobATmindspringDOTcom@nntp6.atl.mindspring.net (Albert) wrote:

:   function(int);
:
: Umm, you get the idea. If int were a class with a default constructor,
: I don't see why it wouldn't be allowed.

    function(int());

You need to pseudocall the constructor.

John
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Artem Hodyush" <artem@duma.gov.ru>
Date: 1999/09/07
Raw View
Albert wrote in message <8E38E30D4artfulbobmindspringc@news.mindspring.com>...
>I hope the title is correct. Can anyone tell me why the
>following won't work?
>
>int function(int x)
>{
>  x = 10;
>}
>
>int main()
>{
>  function(int);
>}
>
>Umm, you get the idea. If int were a class with a default constructor,
>I don't see why it wouldn't be allowed.

Because it should be written as function( int() ), exactly as if int was
a class with default counstructor.

---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]