vector of function pointers problem

Hello.

Here's the problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
typedef bool (*eventcallback)(Window*, INTERFACE*, unsigned, long);

bool deflistener(Window* wnd, INTERFACE* inter, unsigned etype, long param){
	return true;
};

unsigned Controller::createWindow(unsigned w, unsigned h){
	if(!f_ok)
		return NULL;
	std::vector<eventcallback> listeners;
	listeners.push_back(deflistener);
	Window* tmpWnd= new Window(w,h, this, &listeners);
	if(tmpWnd->isInitialized()){
		g_windows.push_back(tmpWnd);//Sucsess! I hupe...
		return tmpWnd->getID();
	}
	return 0;
};


creates the following error:


1>c:\program files\microsoft visual studio 9.0\vc\include\xutility(1850) : error C2296: '-' : illegal, left operand has type 'bool (__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long)'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(1867) : see reference to function template instantiation 'void std::_Distance2<bool(__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long),_Diff>(_RanIt,_RanIt,_Diff &,std::random_access_iterator_tag)' being compiled
1> with
1> [
1> _Diff=unsigned int,
1> _RanIt=bool (__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long)
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\vector(937) : see reference to function template instantiation 'void std::_Distance<bool(__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long),unsigned int>(_InIt,_InIt,_Diff &)' being compiled
1> with
1> [
1> _InIt=bool (__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long),
1> _Diff=unsigned int
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\vector(889) : see reference to function template instantiation 'void std::vector<_Ty>::_Insert<bool(__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long)>(std::_Vector_const_iterator<_Ty,_Alloc>,_Iter,_Iter,std::forward_iterator_tag)' being compiled
1> with
1> [
1> _Ty=GLWinFac::eventcallback,
1> _Alloc=std::allocator<GLWinFac::eventcallback >,
1> _Iter=bool (__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long)
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\vector(866) : see reference to function template instantiation 'void std::vector<_Ty>::insert<bool(__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long)>(std::_Vector_const_iterator<_Ty,_Alloc>,_Iter,_Iter)' being compiled
1> with
1> [
1> _Ty=GLWinFac::eventcallback,
1> _Alloc=std::allocator<GLWinFac::eventcallback >,
1> _Iter=bool (__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long)
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\vector(853) : see reference to function template instantiation 'void std::vector<_Ty>::_Assign<bool(__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long)>(_Iter,_Iter,std::input_iterator_tag)' being compiled
1> with
1> [
1> _Ty=GLWinFac::eventcallback,
1> _Iter=bool (__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long)
1> ]
1> h:\other\planet\graphic\opengl\fixed function 2d 0x1\glwinfac window.h(35) : see reference to function template instantiation 'void std::vector<_Ty>::assign<bool(__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long)>(_Iter,_Iter)' being compiled
1> with
1> [
1> _Ty=GLWinFac::eventcallback,
1> _Iter=bool (__cdecl *)(GLWinFac::Window *,GLWinFac::INTERFACE *,unsigned int,long)
1> ]



A short look at the xutility code and youll see that it's trying to calculate an int out of my func pointers [unsigned int]_Off += [eventcallback]_Last - [eventcallback]_First;



Please help
the code looks all right.. atleast what im able to look at. can you tell which line is giving error?
because i wrote a code close to above code and its running fine.

Thanks for the reply.

Its the std::vector<eventcallback> listeners; the 10th line. At least from what I can figure; If I comment .push_back its same, if i comment both than it goes away.


no line 10 and 11 dont have any errors.
ok lets build the code incremently and find out where is the error. just compile this part.
if this didnt give error then the error is in the commented part.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
typedef bool (*eventcallback)(Window*, INTERFACE*, unsigned, long);

bool deflistener(Window* wnd, INTERFACE* inter, unsigned etype, long param){
	return true;
};

unsigned Controller::createWindow(unsigned w, unsigned h)
{
	if(!f_ok)
		return NULL;
	std::vector<eventcallback> listeners;
	listeners.push_back(deflistener);
/**
	Window* tmpWnd= new Window(w,h, this, &listeners);
	if(tmpWnd->isInitialized()){
		g_windows.push_back(tmpWnd);//Sucsess! I hupe...
		return tmpWnd->getID();
	}
*/
	return 0;
};
I've done that and soon figured exactly what is causing the error.

At my Window constructor there is a

g_callbacks.assign(listeners->front(), listeners->back());//Copy all listeners

which should copy all listeners from the given pointer to a local vector to give us full controll.

How should I do that?

THanks
i need to see what is the declaration of g_callbacks and assign function.
and your windows constructor. then only i can comment anything.
looks g_callbacks is a vector. in that case if g_callbacks and listeners are of the same type then a normal assign will do.

1
2
g_callbacks.clear();
g_callbacks = listeners;
that worked like a charm.


Apprechiated!
hmm.. great.. :)
Topic archived. No new replies allowed.