Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > returning a void (*)(void)

Reply
Thread Tools

returning a void (*)(void)

 
 
Sergio
Guest
Posts: n/a
 
      01-05-2005
If I have a private member:

void (*func)(void);

how can i declare a 'get' function that returns it? I tryed:

void (*)()GetFunc()
{
return func;
}

but looks like that's not the way...

thanks

 
Reply With Quote
 
 
 
 
Bob Hairgrove
Guest
Posts: n/a
 
      01-05-2005
On 5 Jan 2005 03:57:37 -0800, "Sergio" <> wrote:

>If I have a private member:
>
>void (*func)(void);
>
>how can i declare a 'get' function that returns it? I tryed:
>
>void (*)()GetFunc()
>{
> return func;
>}
>
>but looks like that's not the way...
>
>thanks


It's easier with a typedef:

typedef void (* func_t)();

struct C {
func_t func;
func_t getFunc() { return func; }
};

--
Bob Hairgrove

 
Reply With Quote
 
 
 
 
Dietmar Kuehl
Guest
Posts: n/a
 
      01-05-2005
Sergio wrote:
> If I have a private member:
>
> void (*func)(void);


Note that this signature matches a member only if the member
is static: otherwise the type is more something like this

| void (C::*func)(void);

where 'C' is the class containing the member.

> how can i declare a 'get' function that returns it? I tryed:
>
> void (*)()GetFunc()


| void (*GetFunc())()

is the syntax for a void function returning void.
--
<private.php?do=newpm&u=> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

 
Reply With Quote
 
owl ling
Guest
Posts: n/a
 
      01-05-2005
well, yoiu should writen as the following code.
typedef void (*FUNC)(void);

void Func(void)
{
cout << "func" << endl;
}
FUNC GetFunc()
{
FUNC fp = Func;
return fp;
}

 
Reply With Quote
 
msalters
Guest
Posts: n/a
 
      01-05-2005

Sergio wrote:
> If I have a private member:
>
> void (*func)(void);
>
> how can i declare a 'get' function that returns it? I tryed:
>
> void (*)()GetFunc()
> {
> return func;
> }
>
> but looks like that's not the way...


Don't try it this way, use a typedef.

typedef void(*fun_void_void)();
fun_void_void func;
fun_void_void GetFunc() { return func; }
HTH,
Michiel Salters

 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      01-05-2005
msalters wrote:
> Sergio wrote:
> > If I have a private member:
> >
> > void (*func)(void);
> > how can i declare a 'get' function that returns it? I tryed:

>
> Don't try it this way, use a typedef.
>
> typedef void(*fun_void_void)();
> fun_void_void func;
> fun_void_void GetFunc() { return func; }


Another option is to typedef the function type (rather than the
pointer-to-function). I only mention this because it hadn't
occurred to me that it was possible until recently, and I prefer
to avoid pointer typedefs if I can:

| typedef void (fun_void_void) ();
| fun_void_void func; // this declares a function
| fun_void_void *ptr_func = func;
| fun_void_void * GetFunc() { return ptr_func; }

or

| fun_void_void * GetFunc() { return func; }

because the name of a function is converted to a pointer to
that function, in a value context.

 
Reply With Quote
 
Jonathan Turkanis
Guest
Posts: n/a
 
      01-05-2005
Sergio wrote:
> If I have a private member:
>
> void (*func)(void);
>
> how can i declare a 'get' function that returns it? I tryed:


On more way:

#include <boost/mpl/identity.hpp>

using namespace boost::mpl;

identity<void (*)(void)>::type get();


 
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 the difference between void proba(); and void proba(void); ??? PencoOdStip@gmail.com C++ 1 05-23-2007 07:12 PM
what is the difference, void func(void) and void fucn() noblesantosh@yahoo.com C Programming 5 07-22-2005 04:38 PM
"void Method()" vs "void Method(void)" Ollej Reemt C++ 7 04-22-2005 03:47 AM
[Slightly OT] Casting non-void function results to void in modern compilers. David M. Wilson C Programming 8 01-07-2004 07:32 AM
`void **' revisited: void *pop(void **root) Stig Brautaset C Programming 15 10-28-2003 09:03 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57