🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Paul D. DeRocco Sun, 18 Feb 1996 02:14
Returning void
#3450
Author: Paul D. DeRocco
Date: Sun, 18 Feb 1996 02:14
34 lines
1813 bytes
The C++ standard doesn't allow a return statement with an expression to 
be used in a function whose return type is void.

I suggest that it should be legal to return a void expression from a 
function whose type is void. Why? It can be useful in templates. 
Consider the following:

    template <class T, class R> class Functor {
    public:
        R& operator()() { return (obj.*mem)(); }
        Functor(T& o, R& (T::*m)()): obj(o), mem(m) {}
    private:
        T& obj;
        R& (T::*mem)();
    }

This defines a functor containing a pointer to an object to be operated 
on, and a pointer to a member function defined for that object. It 
should work for any member function that takes no arguments and returns 
a result. Unfortunately, it won't work for a member function that 
returns void. If return were modified as described above, this function 
template would work for member functions that return void as well.

-- 

Ciao,
Paul D. DeRocco

[ To submit articles: Try just posting with your newsreader.  If that fails,
		      use mailto:std-c++@ncar.ucar.edu
  FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]
Re: Returning void
#3386
Author: Michael Cook
Date: Tue, 20 Feb 1996 18:46
13 lines
1264 bytes
>>>>> "P" == "Paul D DeRocco" <pderocco@ix.netcom.com> writes:

 P>         R& operator()() { return (obj.*mem)(); }

You're trying to return a `void&', not a `void'.
Surely we wouldn't want the standard to allow `void&'.
---
[ To submit articles: Try just posting with your newsreader.  If that fails,
                      use mailto:std-c++@ncar.ucar.edu
  FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std.c++-request@ncar.ucar.edu 
]
Re: Returning void
#3411
Author: Fergus Henderson
Date: Thu, 22 Feb 1996 20:29
19 lines
1251 bytes
Michael Cook <mcook@cognex.com> writes:

>Surely we wouldn't want the standard to allow `void&'.

No, after all, that might let a tiny little bit of orthogonality
creep into C++, and then who knows what people might want next!

;-)

--
Fergus Henderson             	WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au              	PGP: finger fjh@128.250.37.3

[ To submit articles: Try just posting with your newsreader.
		      If that fails, use mailto:std-c++@ncar.ucar.edu
  FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads