🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3450

Returning void

#3450
From: 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
]
Technical Details
Message-ID: <3125C4A3.5C00@ix.netcom.com>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: "Paul D. DeRocco" <pderocco@ix.netcom.com>
Newsgroups: comp.std.c++
Subject: Returning void
Date: 18 Feb 1996 02:14:49 GMT
Organization: ?
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <3125C4A3.5C00@ix.netcom.com>
NNTP-Posting-Host: taumet.eng.sun.com
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 2.0b6a (Win95; I)
Content-Length: 957
Originator: clamage@taumet