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 6790095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:41:04+00:00 2026-05-26T17:41:04+00:00

I am using Microsoft Visual Studio 2010 and the OpenCV 2.3.0 libraries to write

  • 0

I am using Microsoft Visual Studio 2010 and the OpenCV 2.3.0 libraries to write up an application for image processing.

I have a piece of code that is erroneous for me and I am not sure how to fix it. I am implementing an application where there will be 2 or 3 windows open at the same time and I want each one of them to be assigned with a different CvMouseCallback function. I want all these CvMouseCallback functions to be in a different class together with another function that returns a pointer to one of these functions according to what the user selects.

My Window.h contains this piece of code.

class Window
{
public:
   ... // constructors and destructors
   void setMouseHandler( CvMouseCallback mouseHandler );
private:
   ... // other stuff
};

and Window.cpp

#include "stdafx.h"

void Window::setMouseHandler( CvMouseCallback mouseHandler )
{
    cvSetMouseCallback( win, mouseHandler, NULL );
}

Now, the MouseHandler.h file

class MouseHandler
{
public:
   ...
   CvMouseCallback selectHandler( int option );
   void __cdecl selectROI( int event, int x, int y, int flags, void *param );

private:
   Image *in;
   Window *win;
   void ( CV_CDECL MouseHandler::*callback )( int event, int x, int y, int flags, void *param );
};

and lastly, in MouseHandler.cpp I contain

void __cdecl MouseHandler::selectROI( int event, int x, int y, int flags, void *param )
{
   //do something
}

CvMouseCallback MouseHandler::selectHandler( int option )
{
   callback = (MouseHandler::selectROI);
   return callback;
}

The last bit of information you might need is the definition of CvMouseCallback from the OpenCV library which is

typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, void* param);

Now, the question is: When I return the callback from the last function in MouseHandler.cpp it is underlined with an error saying:

Error: return value type does not match the function type.

I know what it says is that I am trying to impose to that function to return something that does not look like the object it is being asking for. However, it’s just a function and if I could do that in the main class it would be ok. My problem is how can selectHandler return a pointer to the selectROI function so that it can be used by another class?

  • 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-05-26T17:41:04+00:00Added an answer on May 26, 2026 at 5:41 pm

    I think that you need to use a static function here:

    static void __cdecl selectROI( int event, int x, int y, int flags, void *param );
    

    and

    void ( CV_CDECL *callback )( int event, int x, int y, int flags, void *param );
    

    accordingly.

    The thing is that this definition:

    typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, void* param);
    

    Is not a class member function, while yours is a member of class MouseHandler, which means its a different signature and different parameter list (to accommodate for this). Using static class member function solves it for you.

    You’ll have to figure out how to pass the object context data to the static function of course.

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

Sidebar

Related Questions

I have a website which was created using Microsoft Visual Studio 2010. I want
im writing an application using Visual Studio 2010 Express Edition. I have a problem
I have a C++/CLI app that is built under Visual Studio 2010 but using
What have I done? I'm using Microsoft Visual Studio 2010 1) I downloaded libevent-2.0.16-stable
I'm trying to debug MVC source code in Visual Studio 2010 using the Microsoft
I am using Microsoft Visual Studio 2010 and C++ language that runs on the
I'm trying to write a dll plugin for Winamp. I'm using Microsoft Visual Studio
I'm using Microsoft Visual Studio 2010. When I add files to my project, they
I'm using Microsoft Visual Studio 2008 (VC9) to compile a project that has a
I am new to using Microsoft development tools but have been using Visual Studio

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.