Having problems with the following...

// this is contained within "UF_styler.h" and can not be alternate
...

[B]typedef int (*UF_STYLER_cb_f_t)(int dialog_id, 
                            void *client_data, 
                            UF_STYLER_item_value_type_p_t call_data);[/B]

struct UF_STYLER_callback_info_s {
        char              *object_id;
        int                cb_type;
        int is_dialog_launching_cb;
        [B]UF_STYLER_cb_f_t   callback_proc;[/B]
};

typedef struct UF_STYLER_callback_info_s UF_STYLER_callback_info_t,
                                        *UF_STYLER_callback_info_p_t;

....
// my dialog.hxx file
#ifndef UIDIALOG_HXX_INCLUDED
#define UIDIALOG_HXX_INCLUDED

#include <UF_styler.h>

class UIEntryPoint
{
public:
  UIEntryPoint(void);
  virtual ~UIEntryPoint(void);

  int Dialog(void);

private:
  int ok_cb(int dialog_id, void *client_data, 
               UF_STYLER_item_value_type_p_t cb);

  int cancel_cb(int dialog_id, void *client_data, 
                   UF_STYLER_item_value_type_p_t cb);
};

#endif // UIDIALOG_HXX_INCLUDED
// my dialog.cpp file
#include ".\UIEntryPoint.hxx"

UIEntryPoint::UIEntryPoint(void) {}

UIEntryPoint::~UIEntryPoint(void) {}

int UIEntryPoint::Dialog(void)
{
  const unsigned COUNT = 3;

  UF_STYLER_callback_info_t CBS[COUNT] =
  {
    {"UF_STYLER_DIALOG_INDEX", UF_STYLER_OK_CB, 0, ok_cb},
    {"UF_STYLER_DIALOG_INDEX", UF_STYLER_CANCEL_CB, 0, cancel_cb},
    {"UF_STYLER_NULL_OBJECT" , UF_STYLER_NO_CB, 0, 0}
  };

  return (response);
}

int UIEntryPoint::ok_cb(int dialog_id, void *client_data,
                             UF_STYLER_item_value_type_p_t cb)
{ 
  return (UF_UI_CB_EXIT_DIALOG); 
}

int UIEntryPoint::cancel_cb(int dialog_id, void *client_data, 
                             UF_STYLER_item_value_type_p_t cb)
{ 
  return (UF_UI_CB_EXIT_DIALOG);
}

When I comply I get the following error...
error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'UF_STYLER_cb_f_t'

Any help would be greatly appreciated!!!

I had this solved before about three years ago, but for the life of me, I can not find that code and forgot how I solved it.

Best Regards

Recommended Answers

All 8 Replies

First, thank you Radical E. for a fast reply.

But, i'm still confused.
I read and tried what the C++ FAQ desrcibed but without success.
Can you give more detail on the syntax.
I know how to do it with static pointers to member functions (methods) but I prefer not to have them as static, it makes it a pain accessing the private data members (properties) of the owning instance.

Any more help would be great.

Best Regards.

When you declare the typedef, be sure to place a forward declaration for the class so you can use the name:

class UIEntryPoint;

typedef int (UIEntryPoint::*UF_STYLER_cb_f_t)(
  int dialog_id, void *client_data, UF_STYLER_item_value_type_p_t call_data);

Assigning the methods to each pointer goes like this:

int UIEntryPoint::Dialog(void)
{
  const unsigned COUNT = 3;

  UF_STYLER_callback_info_t CBS[COUNT] =
  {
    {"UF_STYLER_DIALOG_INDEX", 0, 0, &UIEntryPoint::ok_cb},
    {"UF_STYLER_DIALOG_INDEX", 0, 0, &UIEntryPoint::cancel_cb},
    {"UF_STYLER_NULL_OBJECT" , 0, 0, 0}
  };

  return (response);
}

The actual call is pretty vicious because the pointer is a member of a struct, but if you're calling the method on the this pointer it would be:

(this->*CBS[0].callback_proc)(<args>);

Radical E, thank you again.

But still having issue...

on this part I get the error below... (I included this at the top of the dialog.hxx)

class UIEntryPoint;

typedef int (UIEntryPoint::*UF_STYLER_cb_f_t)(
  int dialog_id, void *client_data, UF_STYLER_item_value_type_p_t call_data);

error C2373: 'UF_STYLER_cb_f_t' : redefinition; different type modifiers

soooo, I tried the following... (referencing 33.5 for the C++ FAQ)

class UIEntryPoint;

typedef int (UIEntryPoint::*ok_cb)(
  int dialog_id, void *client_data, UF_STYLER_item_value_type_p_t call_data);

typedef int (UIEntryPoint::*cancel_cb)(
  int dialog_id, void *client_data, UF_STYLER_item_value_type_p_t call_data);

now the error for this is against both function pointers within the structure...

error C2440: 'initializing' : cannot convert from 'int (__thiscall UIEntryPoint:: * )(int,void *,UF_STYLER_item_value_type_p_t)' to 'UF_STYLER_cb_f_t'
error C2440: 'initializing' : cannot convert from 'int (__thiscall UIEntryPoint:: * )(int,void *,UF_STYLER_item_value_type_p_t)' to 'UF_STYLER_cb_f_t'

this is against this...

UF_STYLER_callback_info_t CBS[COUNT] =
{
{"UF_STYLER_DIALOG_INDEX", UF_STYLER_OK_CB , 0, &UIEntryPoint::ok_cb},
{"UF_STYLER_DIALOG_INDEX", UF_STYLER_CANCEL_CB , 0, &UIEntryPoint::cancel_cb},
};

sorry to be a pain, I know it can be done, I wish I could find my old code.
I had to do this once before and I burned it to cd but I have over 50 discs of code now, and I can not remember which one its on let along which year it would have been (my disc are labelled by month/year).

thank you again for your time and patience.

I wish I could find my old code.

Somewhat off topic, but anyway, I think you might benefit from having your code under version control, here is one pointer to get you started with it ...
http://subversion.tigris.org/

> error C2373: 'UF_STYLER_cb_f_t' : redefinition; different type modifiers
Did you remove the old typedef? This will give the same error because there are two different typedefs with the same name of UF_STYLER_cb_f_t:

class UIEntryPoint;

typedef int (UIEntryPoint::*UF_STYLER_cb_f_t)(
  int dialog_id, void *client_data, UF_STYLER_item_value_type_p_t call_data);

typedef int (*UF_STYLER_cb_f_t)(
  int dialog_id, void *client_data, UF_STYLER_item_value_type_p_t call_data);

Radical Ed, thank you for the reply.

> error C2373: 'UF_STYLER_cb_f_t' : redefinition; different type modifiers
Did you remove the old typedef? This will give the same error because there are two different typedefs with the same name of UF_STYLER_cb_f_t:

The member function pointer typedef is defined in the UF_styler.h header file, this file I can not alternate in any way. This is one of many hundreds of library header files provided by the CAD software, Unigraphics. I have to include it just as it is. Does this make sense?

The code we have be working with is used for the dialog button callbacks. The template files Unigraphics UI Styler provide are in standard C, I have successfully created my own version using C++ but all my production applications I have previously deployed declare the callback functions as "static" and this all works. But, I was experiencementing a few years ago and was able to change the callback functions into regular member functions. I am still searching the discs for this code, i do remember it was definitely an unusally approach.

BTW, concerning versioning we have a process in place at GM for production code. The code that I have on the my disc is hundreds (maybe thousands) of practice applications. When not writing production intended code, I do ALOT of practicing.

But, mitrmkar, thank you for the info on the versioning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.