I'm facing a problem with Functors. I have made the following functor class
template <typename classT, typename retT, typename P1>class Functor1{ public: Functor1(classT *state, retT (classT::*func)(P1)) : _func(func), _state(state){} Functor1() : _state(NULL), _func(NULL){} retT operator()(P1 arg) { if(_func != NULL && _state != NULL) return (*_state.*_func)(arg); else return -1; } retT Call(P1 arg) { if(_func != NULL && _state != NULL) return (*_state.*_func)(arg); else return -1; } private: classT *_state; retT (classT::*_func)(P1);};
I have the button class:
namespace Alluminium{ class AlButton : public AlWidget { public: AL_API AlButton(AlWidget *Parent, Point2<int> Size, Point2<int> Position, std::wstring text); AL_API virtual ~AlButton(void); AL_API virtual LRESULT OnLeftClick(Point2<int> MousePosition); template <typename T> Functor1<T, LRESULT, Point2<int>> OnLeftClickCallback; virtual LRESULT HandleEvent(unsigned int msg, WPARAM wParam, LPARAM lParam); };}
And the functor is called like:
LRESULT AlButton::OnLeftClick(Point2<int> MousePosition){ return OnLeftClickCallback.Call(MousePosition);}
But I get the below compiler error and then I get a message that the "Microsoft(R) Optimized C\C++ Compiler" crashed
Quote:
1>albutton.hpp(20): fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'msc1.cpp', line 1420)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
Can anybody tell me why the compiler crashes and how I should fix this?
Thanks in advance,
assainator