473,387 Members | 1,779 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,387 software developers and data experts.

circular function pointers declaration?

Hi,

Is it possible to declare a function pointer whose arguments is a pointer to
a function pointer of the same type? Something like:

=====
typedef unsigned long (*myFuncPtr) (myFuncPtr*);
=====

The above is not working and generates the error below:
=====
test.cpp:5: error: `myFuncPtr' was not declared in this scope
test.cpp:5: error: syntax error before `)' token
=====

Is there a way to declare a dummy myFuncPtr earlier so I can use the name as
an argument?

Thanks!
Tim.
Apr 27 '06 #1
3 1967
Timothee Groleau wrote:
Hi,

Is it possible to declare a function pointer whose arguments is a pointer to
a function pointer of the same type? Something like:

=====
typedef unsigned long (*myFuncPtr) (myFuncPtr*);
=====


OPTION A
----------------------------------------------
Simply:

typedef unsigned long (*myFuncPtr) (void*);

Just be careful to cast your pointers to void*.
OPTION B
----------------------------------------------
Abstract base class approach:

class my_itf
{
public:
virtual unsigned long
operator()(my_itf& pnext) = 0;
};

template <unsigned long N>
class my_itf_end: public my_itf
{
public:
unsigned long operator()(my_itf&)
{
return N;
}
};

which can be used like:

class A: public my_itf
{
public:
unsigned long operator()(my_itf& next)
{
return next(my_itf_end<5>());
}
};

int main()
{
A a;
my_itf& f = a;

f(f);
}

Pick your poison :)

Regards,
Ben
Apr 27 '06 #2

Timothee Groleau wrote:
Hi,

Is it possible to declare a function pointer whose arguments is a pointer to
a function pointer of the same type?


No, this was a Guru Of The Week question. (www.gotw.ca)

HTH,
Michiel Salters

Apr 27 '06 #3
benben wrote:
Pick your poison :)

Regards,
Ben


Thanks Ben!

Apr 28 '06 #4

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

Similar topics

3
by: crichmon | last post by:
Any general advice for dealing with circular dependencies? For example, I have a situation which, when simplified, is similar to: ///////////// // A.h class A { public: int x;
18
by: ma740988 | last post by:
I think I'm caught up in a circular dependency problem. I'd thought forward declaration was the solution to my problem but I'm sadly mistaken (perphaps i've been in the lab toooo long today). The...
6
by: Markus Dehmann | last post by:
I have a circular dependency between two classes. The FAQ hint about a forward declaration does not help in my case ( How can I create two classes that both know about each other?) Error:...
16
by: Kiuhnm | last post by:
Is there an elegant way to deal with semi-circular definitions? Semi-circular definition: A { B }; B { *A }; Circular reference: A { *B }; B { *A }; The problems arise when there are more...
3
by: Dennis Chang | last post by:
Hi all, I was reading about function pointers and came across something which intrigued me. K&R2 calls qsort (pg.119) within main as so: qsort( (void **) lineptr, 0, nlines-1, (int (*) (void...
6
by: T Koster | last post by:
After a few years of programming C, I had come to believe that I finally knew how to correctly organise my structure definitions in header files for mutually dependent structures, but I find myself...
6
by: Jordi | last post by:
I'm having a problem which I think has to do with the circular use of inlcuding header files. The short version of my code would look a bit like this, I think: GameEngine.h: #ifndef GAME_ENGINE...
5
by: fomas87 | last post by:
Hi guys, I'm writing a framework for an sdl gui in c++, but got stuck on the circular dependency, I've read a lot of articles about resolving dependencies and about forward declaration but none of...
6
by: Mosfet | last post by:
Hi, I have two classes, let's call them class A and class B with mutual dependencies as shown below and where implementation is inside .h (no cpp) #include "classB.h" class A {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.