J
Jan-Henrik Grobe
Hallo,
I am coming to this newsgroup with a very strange Problem. I have two c++
files A.cpp and B.cpp....In A.cpp I am creating an openGL window and in
B.cpp I have stored the callback functions. Important is, that the object
A.o has to be created BEFORE B can be compiled. I am sure that sounds
confusing but A.cpp is part of a library that is needed for objects I use in
B (kind of client-server thing). So I cannot include a B.h in the A.cpp. But
B.cpp has an include A.h. I thought of using function pointers and my code
looks something like this:
In A.h the function pointer is defined
A.h
....
extern void (*pDisplay)(void); // Definition of a function
pointer pDisplay
....
Because I have to use "extern" (doesnt work other) I have to declare
something to the pointer in A.cpp. I thought of using a dummy funtion:
A.cpp
void dummy(void)
{
cout << I am a stupid dummy function <<;
}
pDisplay = dummy; // assign adress to dummy to pDisplay (NULL doesnt
work)
later I create an open GL window and give the pointer as the display
callback
....
window = glutCreateWindow(...);
glutDisplayFunc(pDisplay);
But the function that should be the display function is in B.cpp
B.cpp
....
void displayWindow(void)
{
// Displaycallbackfunction
}
B is exectueable and has a main function. There...first an object has to be
created that uses a library that contains A.cpp ... then I want to pass
displayWindow to the pointer pDisplay that is defined in A.h
int main (argc, argv)
{
create an object O;
pWindow = displayWindow; // assign displayWindow to the pointer
pDisplay
ok....the code compiled and linked fine. The problem now is, when I execute
it, that the pointer pDisplay keeps the whole time the adress of the dummy
function and not the adress of displayWindow. I thought you can assign
functions to pointers at the runtime somehow. If I assign the adress of
displayWindow to the pointer before the object O is created, I get a memory
error. In my opinion it must have something to do with the keyword "extern"
in the A.h. If I wouldnt need to declare the pointer in the A.cpp then maybe
I wont have this problem. Unhappily I am not very familiar with function
pointers. I used information i found in the net but obviously with less
success. Maybe one of you has a little hint for me or a good advise.
Many thanks
Jan-Henrik
I am coming to this newsgroup with a very strange Problem. I have two c++
files A.cpp and B.cpp....In A.cpp I am creating an openGL window and in
B.cpp I have stored the callback functions. Important is, that the object
A.o has to be created BEFORE B can be compiled. I am sure that sounds
confusing but A.cpp is part of a library that is needed for objects I use in
B (kind of client-server thing). So I cannot include a B.h in the A.cpp. But
B.cpp has an include A.h. I thought of using function pointers and my code
looks something like this:
In A.h the function pointer is defined
A.h
....
extern void (*pDisplay)(void); // Definition of a function
pointer pDisplay
....
Because I have to use "extern" (doesnt work other) I have to declare
something to the pointer in A.cpp. I thought of using a dummy funtion:
A.cpp
void dummy(void)
{
cout << I am a stupid dummy function <<;
}
pDisplay = dummy; // assign adress to dummy to pDisplay (NULL doesnt
work)
later I create an open GL window and give the pointer as the display
callback
....
window = glutCreateWindow(...);
glutDisplayFunc(pDisplay);
But the function that should be the display function is in B.cpp
B.cpp
....
void displayWindow(void)
{
// Displaycallbackfunction
}
B is exectueable and has a main function. There...first an object has to be
created that uses a library that contains A.cpp ... then I want to pass
displayWindow to the pointer pDisplay that is defined in A.h
int main (argc, argv)
{
create an object O;
pWindow = displayWindow; // assign displayWindow to the pointer
pDisplay
ok....the code compiled and linked fine. The problem now is, when I execute
it, that the pointer pDisplay keeps the whole time the adress of the dummy
function and not the adress of displayWindow. I thought you can assign
functions to pointers at the runtime somehow. If I assign the adress of
displayWindow to the pointer before the object O is created, I get a memory
error. In my opinion it must have something to do with the keyword "extern"
in the A.h. If I wouldnt need to declare the pointer in the A.cpp then maybe
I wont have this problem. Unhappily I am not very familiar with function
pointers. I used information i found in the net but obviously with less
success. Maybe one of you has a little hint for me or a good advise.
Many thanks
Jan-Henrik