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

Function pointers and forward declaration

hi !!

i have i function pointer that i declared in unmanaged code:

void (*func_ptr)();

and i have a managed class where i need to assign a pointer to this
function pointer and then call it. check out this code:

ref class MyClass; // forward declaration

void Func() {
MyClass::MyStaticFunc(); // this generates C3083, C2039 and C3861
}

public ref class MyClass {
public:
MyClass() {
func_ptr = &Func;
func_ptr();
}

static void MyStaticFunc() {
}
};

----------------------------------------------------------

as you can see my compiler won't accept the forward declaration...
i have also tried assigning func_ptr = &MyStaticFunc which won't work
unless MyStaticFunc is a delegate...

any clues??? please....

THANKS ALOT!

Jan 14 '07 #1
1 1558
On 14 Jan 2007 14:20:29 -0800, to**********@hotmail.com wrote:
>hi !!

i have i function pointer that i declared in unmanaged code:

void (*func_ptr)();

and i have a managed class where i need to assign a pointer to this
function pointer and then call it. check out this code:

ref class MyClass; // forward declaration

void Func() {
MyClass::MyStaticFunc(); // this generates C3083, C2039 and C3861
}

public ref class MyClass {
public:
MyClass() {
func_ptr = &Func;
func_ptr();
}

static void MyStaticFunc() {
}
};

----------------------------------------------------------

as you can see my compiler won't accept the forward declaration...
i have also tried assigning func_ptr = &MyStaticFunc which won't work
unless MyStaticFunc is a delegate...

any clues??? please....
You can't use incomplete classes in that way. The function Func needs to
see the definition of MyClass in order to call MyStaticFunc, so rearranging
things like this should work:

void Func();

public ref class MyClass {
public:
MyClass() {
func_ptr = &Func;
func_ptr();
}

static void MyStaticFunc() {
}
};

void Func() {
MyClass::MyStaticFunc(); // this generates C3083, C2039 and C3861
}

--
Doug Harrison
Visual C++ MVP
Jan 15 '07 #2

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

Similar topics

5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
4
by: Oystein Haare | last post by:
Is it best to declare class member objects as pointers or not pointers? class A { public: A(int i); //.... };
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...
10
by: gmtonyhoyt | last post by:
It's been mentioned to me that, in standard c, that you can have structures behave very much like classes in relation to something to do with function calls within a structure. Now, I didn't get...
5
by: goldfita | last post by:
I have the following two prototypes in separate source files. Both programs compile and work correctly. (1) void general_foo(void (*foo)(), int opt, ...); (2) static int...
5
by: Bob | last post by:
The title says it all. The nextmon() and prevmon() functions are listed afterward, since they call fDrawCal().I'm sure you see the problem...prevmon() is not defined prior to being mentioned in the...
1
by: yancheng.cheok | last post by:
currently, i have a private function in cat named privateFun. i would like to have this function "private" to all except dog's action member function. by using the following approach, all the...
12
by: Googy | last post by:
Hi!! Can any one explain me the meaning of following notations clearly : 1. typedef char(*(*frpapfrc()))(); frpapfrc f; 2. typedef int (*(arr2d_ptr)()); arr2d_ptr p; 3. typedef int...
6
by: Syren Baran | last post by:
Hi, is it possible to write two functions which both require a function as an argument and both being able to use the other function as an argument? Afaik the address of a function is not known...
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
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:
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
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,...
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
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.