Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8639029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:53:42+00:00 2026-06-12T10:53:42+00:00

I have a Button class: class Button : public Component { private: SDL_Rect box;

  • 0

I have a Button class:

class Button : public Component {

private:
    SDL_Rect box;
    void* function;

public:
    Button( int x, int y, int w, int h, void (*function)() );
    ~Button();
    void handleEvents(SDL_Event event);

};

And I want to execute Button::function in the method Button::handleEvents:

void Button::handleEvents(SDL_Event event) {
    int x = 0, y = 0;
    // If user clicked mouse
    if( event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) {
            // Get mouse offsets
            x = event.button.x;
            y = event.button.y;

            // If mouse inside button
            if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
            {
                this->function();
                return;
            }
    }

}

When I try to compile, I get the following errors:

Button.cpp: In the constructor ‘Button::Button(int, int, int, int, void (*)(), std::string)’:
Button.cpp:17:18: error: invalid conversion from ‘void (*)()’ to ‘void*’ [-fpermissive]
Button.cpp: In the function ‘virtual void Button::handleEvents(SDL_Event)’:
Button.cpp:45:19: error: can't use ‘((Button*)this)->Button::function’ as a function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:53:43+00:00Added an answer on June 12, 2026 at 10:53 am

    The function pointer in your private section is not declared as it should be.

    It should be :

    void (*functionPtr)();
    

    Look at this question for more info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called Mouse (tracking button states in a game). I want
I have made a small custom view component: public class ActionBar extends RelativeLayout {
I have created a button CSS class that uses background images with different positions
I have created my own button class called custom_btn. I created it on the
I have some class SimpleButton . It is a Child of Button class. Button
I have a button that can have a focus css class associated with it
I have a Button and the button content is binded to a custom class
I have crated a class which extends the ListFragment . I have one button
I have a Main class and a HelloWorld class. I have created a button
I have a custom ButtonUI class that paints the button. Before drawing the text,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.