473,395 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

returning a void (*)(void)

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

Jul 22 '05 #1
6 1996
On 5 Jan 2005 03:57:37 -0800, "Sergio" <se*******@gmail.com> 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
No**********@Home.com
Jul 22 '05 #2
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.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

Jul 22 '05 #3
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;
}

Jul 22 '05 #4

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

Jul 22 '05 #5
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.

Jul 22 '05 #6
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();
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jochen Zeischka | last post by:
I'm puzzled. When compiling this: template<class ValRes, class Val1, class Val2> Veld<ValRes>& mult(Veld<ValRes>& res, const Veld<Val1>& v1, const Veld<Val2>& v2) { // something return res; }...
19
by: JKop | last post by:
When I compile and run the following on my system: #include <iostream> static int hello = 78; int ReturnValue(void) {
7
by: BrianJones | last post by:
Hi, if you have a function, how is it possible to return an array? E.g.: unsigned long function(...) // what I want to do, obviously illegal I do know such would be possible by using a dynamic...
41
by: Materialised | last post by:
I am writing a simple function to initialise 3 variables to pesudo random numbers. I have a function which is as follows int randomise( int x, int y, intz) { srand((unsigned)time(NULL)); x...
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
6
by: Generic Usenet Account | last post by:
Is it okay to return a local datastructure (something of type struct) from a function, as long as it does not have any pointer fields? I think it is a bad idea, but one of my colleagues does not...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
28
by: Yevgen Muntyan | last post by:
Hey, Consider the following code: void func (void) { } void func2 (void) {
3
by: John Turner | last post by:
typedef void (*vfp)(); typedef vfp (*fp)(); static fp hello() { printf("Hello.\n"); return (fp)&hello; } main(){
7
by: TBass | last post by:
Hi. I wrote a "tag" class to store values. The user gets to store most any type he would need. Instead of getting too complicatated, I decided I would store the value as a stringstream, then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.