std::function issue C2664

Hello

Could I request a help in following problem?

I have a base class called cParent. It's child is cChild

//This is a sharedPtr. I have 1000's of this type and for issue description purpose, I just took one here.
DataObjectEnumSharedPtr mySharePtr1;
DataObjectEnumSharedPtr mySharePtr2;
................
................
DataObjectEnumSharedPtr mySharePtr1000;

//If I use this, map insertion is throwing compile error
//This is to make the function pointer
typedef void(cParent::*ddEnumParamFP)(DataObjectInt*);


//It is working but I want above one and that is ultimate aim
//This is to make the function pointer
typedef void(cChild::*ddEnumParamFP)(DataObjectInt*);



//I use this map to insert the sharedPtr and an associated callback function's function pointer
map <DataObjectSharedPtr, ddEnumParamFP> m_enumDDMap;


Utilclass::insert()
{

//I have a function to initialize mySharePtr1 to mySharePtr1000
//It is working fine so I am not adding function here.
initialize_shareptrs();


//See this is working absolutely fine if I use cChild::
m_enumDDMap.insert(std::make_pair(m_eFeatureSeats_DISPLAYEDSTATE, &cChild::oneFeatureSeats_DisplayedState));


//But following is not working
m_enumDDMap.insert(std::make_pair(m_eFeatureSeats_DISPLAYEDSTATE, &iIcimNode2::oneFeatureSeats_DisplayedState));

}

cChild is a child class of cParent.


How can I use cParent instead of cChild?

Cheers
Nidhin

Last edited on
It would be more helpful if you:
* provide minimal code that reproduces the error
* post the exact error the compiler reports
Sure. I will

The thing is,

I have 5 classes.. and all of them have same base class. In each class I have M signals and it's corresponding callback functions. I wish to keep the callback functions in the child class but wish to move all the signals to a seperate class. This will reduce the lines of codes.

class Base
{

}

class Child1: public Base
{

sharedPtr1Signal
sharedPtr2Signal
sharedPtr3Signal
sharedPtr4Signal
.......
sharedPtrnSignal

callback1
callback2
....
callback n
}

class Child2: public Base
{

sharedPtr1Signal
sharedPtr2Signal
sharedPtr3Signal
sharedPtr4Signal
.......
sharedPtrnSignal


callback1
callback2
....
callback n
}
..
...
class Child5: public Base
{

sharedPtr1Signal
sharedPtr2Signal
sharedPtr3Signal
sharedPtr4Signal
.......
sharedPtrnSignal

callback1
callback2
....
callback n
}


In the present implementation, it is working fine. Where, I have a function pointer as below

// C1 Header
typedef void(C1::*ddEnumParamFP)(DataObjectInt*);
map <DataObjectSharedPtr, ddEnumParamFP> m_enumDDMap;

//C1 CPP
m_enumDDMap.insert(std::make_pair(sharedPtr1Signal, &C1::callback1));
m_enumDDMap.insert(std::make_pair(sharedPtr2Signal, &C1::callback2));
m_enumDDMap.insert(std::make_pair(sharedPtr3Signal, &C1::callback3));

And same for C1,C2,C3,C4,C5

What I wish to do is , moving this code to a new class. Specifically for this operation.
I wish to have a single map for all class. So, when I declare map, ddEnumParamFP should be generic to all C1,C2,C3,C4,C5. Only option is to refer it's base. So I changed from


typedef void(C1::*ddEnumParamFP)(DataObjectInt*); to

typedef void(Base::*ddEnumParamFP)(DataObjectInt*);

and then created map as below
map <DataObjectSharedPtr, ddEnumParamFP> m_enumDDMap;

but this time,
m_enumDDMap.insert(std::make_pair(sharedPtr1Signal, &C1::callback1)); failed and got C2664 error.

Severity Code Description Project File Line Suppression State
Error C2664 'std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>> std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>::insert(std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,const std::pair<const _Kty,_Ty> &)': cannot convert argument 1 from 'std::pair<std::shared_ptr<DirectDataEnum>,void (__thiscall C1::* )(DataObjectInt *)>' to 'std::pair<const _Kty,_Ty>




Last edited on
Topic archived. No new replies allowed.