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

Callback functions

Well, I'll try to keep this short and sweet.

I'm trying to use glut which is a toolkit for OpenGL. Inside this
toolkit are a couple of functions that are giving me a slight problem
with trying to add to a class.

Here is the header for the class I would like to make (simplified and
error checking removed):

namespace myGlut {

class glutWindow {

public:

glutWindow();
glutWindow(std::string name, int x, int y, int w, int h);
void create();
void redraw(int _w, int _h);
void display();
void keyboard(unsigned char _k, int _x, int _y);
void loop();

private:

std::string title;
int xpos, ypos, width, height;
};
}

Now the details aside the method I'm really looking at here is the
create() method.

Inside this method is a call to a function inside the glut toolkit.
Here is the prototype for that function:

void glutDisplayFunc( void(*func)() );

Which as I see it, takes an address to a function (function pointer and
all that rot.)

However, the problem is that I would like to pass
myGlut::glutWindow::display() as the callback function.

therefore in my code I make a call like so:

void glutWindow::create() {

//Some really boring init stuff.
:
:
//Create a window with data members: title, xpos, ypos, width,
height.
:
:
glutDisplayFunc(myGlut::glutWindow::display);
:
:
//End of method
}

However, a conversion from void(*)() to void(myGlut::glutWindow::*)()
is not possible. Making things static, I believe but correct me if I'm
wrong, would solve the conversion but would really defeat the purpose
of making a class in the first place.

Finally, I just wanted to let everyone know that I am aware of C++
toolkits that wrap OpenGL, but I believe that what I'm asking is more
along the lines of a much broader question of how does one pass a
member function to some of the older C style functions that are looking
for a format of type(*)(...), eh?

Thanks for all the help!

:-) Cheers and stuff from justyb's desktop!

Nov 22 '05 #1
1 1942

"slack_justyb" <ju******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
However, a conversion from void(*)() to void(myGlut::glutWindow::*)()
is not possible. Making things static, I believe but correct me if I'm
wrong, would solve the conversion but would really defeat the purpose
of making a class in the first place.

Finally, I just wanted to let everyone know that I am aware of C++
toolkits that wrap OpenGL, but I believe that what I'm asking is more
along the lines of a much broader question of how does one pass a
member function to some of the older C style functions that are looking
for a format of type(*)(...), eh?


This is addressed in the FAQ:
http://www.parashift.com/c++-faq-lit....html#faq-33.2
-Mike
Nov 22 '05 #2

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

Similar topics

6
by: Eric Entressangle | last post by:
Hi all, is there any trouble setting an C++ static class method as callback function for a C program or library ? Thanks
5
by: Pratik | last post by:
what are callback functions? Where we require callback functions? In what scenario we require callback functions?
11
by: ajay.sonawane | last post by:
Hello ther I read somewhere that callback function should be global or static member function. 1: I could use static member functions but how could I access members of class which ar not static....
15
by: Felix Kater | last post by:
Hi, in a given library I register callback functions with this function: bool set_callback(int index, int (*callback_function)(long)); I need the callback function to also pass the index...
4
by: Jimmy | last post by:
I need to use Asynchronous Socket functions in a server application and am learning from sources such as the MSDN2 (http://msdn2.microsoft.com/en-us/library/bbx2eya8.aspx). What I observed is that...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
2
by: Evan Burkitt | last post by:
Hi, all. I have a Windows DLL that exports a number of functions. These functions expect to receive a pointer to a callback function and an opaque void* parameter. The callback functions are...
1
by: kikivenkat | last post by:
Hi, I understand the concept of function pointers. I am a little confused with the call back functions. 1.If a function is invoked using a function pointer, then does it mean the function...
5
by: Jef Driesen | last post by:
I have a C DLL that I want to use from a C# project. The C header file contains these declarations: typedef void (*callback_t) (const unsigned char *data, unsigned int size, void *userdata);...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.