glutdisplay function

Posted on 2008-06-13
Medium Priority
Last Modified: 2013-12-21
I want to have the class object as a parameter in Display(common *s) function (where common is a class)  which is called in glutDisplayFunc(Display)
 But it shows error that i should not use parameters in display func.....Is there any way to  do it....?
Question by:jsbsudha
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 53

Accepted Solution

Infinity08 earned 2000 total points
ID: 21777913
>> But it shows error that i should not use parameters in display func.....

That is correct. The function pointer passed as argument to glutDisplayFunc Has to have this signature :

        void fun(void);

ie. taking no arguments, and returning nothing.

If you want to have data available to the function, there are several ways of doing that.

1) if the object will always be the same object, you can make it a static local of the function :

        void Display() {
            static common *s;
            /* the code */

2) if the object will change for every call to the function, then you can make it a global :

        common *s;
        void Display() {
            /* the code */

Author Comment

ID: 21778123
At present I had made the object as a global.......so i will come to you after some time.....
LVL 53

Expert Comment

ID: 21778152
>> so i will come to you after some time.....

What do you mean ? Is your question answered, or do you need further assistance with this?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 21778564
As I am working on the task of  converting the procedural way program into object oriented way...... I would like to ask some other doubt regarding this usage of global object....now i could not  accept your solution readily.......if i find that everything works fine if I declare it as a global object......then i can close this question............

Thank you
LVL 53

Expert Comment

ID: 21778602
ok :)
LVL 20

Expert Comment

ID: 21788599
hey jsbsudha, i8 gave you the only possible answer(s) .. please be so kind and pay a little respect to that, dont wait months to close it, it would just be fair to do so, because he tried to help you and he did .. remember its a give and take here .. :)

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question