![dev.gamez.lv Forum Index](templates/subSilver/images/logo_phpBB.gif) |
dev.gamez.lv Latvian Game Developers Community
|
View previous topic :: View next topic |
Author |
Message |
elvman Indago Uzvarētājs
![Indago Uzvarētājs Indago Uzvarētājs](https://forums.gamedev.lv/images/ranks/cup1.gif)
Joined: 09 Apr 2003 Posts: 1278 Location: Kuldiga
|
Posted: Sat Feb 09, 2008 2:03 pm Post subject: pārāk sarežģīta struktūra krašo kompilatoru |
|
Palasīju jauno rakstu GameDev.net un uzrakstiju pats savu message handleri. Kods:
Code: | template <class T> class MemberFunctionHandler
{
public:
typedef void (T::*MemberFunction)(Message*, User*);
MemberFunctionHandler(T* object, MemberFunction memberFunction):
mObject(object), mFunction(memberFunction)
{
}
void Execute(Message* message, User* sender)
{
(mObject->*mFunction)(message, sender);
}
private:
T* mObject;
MemberFunction mFunction;
};
class MessageHandler
{
public:
MessageHandler()
{
}
virtual ~MessageHandler()
{
}
void HandleMessage(Message* message, User* sender)
{
std::map<uint8,MemberFunctionHandler*>::iterator i = mHandlers.find(message->GetType());
if(i != mHandlers.end())
i->second->Execute(message, sender);
}
template <class T> void RegisterEventFunc(uint8 messageType, T* object, void (T::*memberFunction)(Message*, User*))
{
mHandlers[messageType]= new MemberFunctionHandler(object, memberFunction);
}
private:
std::map<uint8,MemberFunctionHandler*> mHandlers;
}; |
Bet problēma tāda, ka nekādi nevaru viņu nokompilēt. Visual C++ 2005 kompilators visu laiku nocrashojas un saka, lai vienkāršoju kodu. Es vairākas reizes pārskatiju kodu, viss ir kā vajag, neko vairs nevar noīsināt. Varbūt kādas idejas, kāpēc tā? Vai arī idejas kā noīsināt vēl? _________________ long time; /* know C */ |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
snake5 Indago dalībnieks
![Indago dalībnieks Indago dalībnieks](https://forums.gamedev.lv/images/ranks/cup2.gif)
Joined: 27 Jun 2007 Posts: 2590
|
Posted: Sat Feb 09, 2008 2:11 pm Post subject: |
|
pilno erroru ieliec maybe?
tā jau nevar atrast īsti, ko vienkāršot.. _________________ "There are two choices here: "looks good" and "realism"." -- Paul Nettle |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
elvman Indago Uzvarētājs
![Indago Uzvarētājs Indago Uzvarētājs](https://forums.gamedev.lv/images/ranks/cup1.gif)
Joined: 09 Apr 2003 Posts: 1278 Location: Kuldiga
|
Posted: Sat Feb 09, 2008 2:14 pm Post subject: |
|
Tas arī ir pilnais errors: cl.exe crashed, try to simplify the program... bla bla bla. _________________ long time; /* know C */ |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
bubu Indago Uzvarētājs
![Indago Uzvarētājs Indago Uzvarētājs](https://forums.gamedev.lv/images/ranks/cup1.gif)
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Sat Feb 09, 2008 2:16 pm Post subject: |
|
Tev tur vispār ir invalīds C++ kods.
MemberFunctionHandler ir klases templeite ar vienu parametru (T).
Taču reku: std::map<uint8,MemberFunctionHandler*> mHandlers;
tu lietot to MemberFunctionHandler bez templeites argumenta specificēšanas.
Btw, šāda veida messagu/eventu handleris nav īpaši labs.
Iesaku paskatīties uz FastDelegate vai libsigc++ vai Boost.Signals + Boost.Funciton.
Btw man tavs koda fragments ne uz MSVC2k5, ne arī uz MSVC2k8 neko nekrašoja - parādīja tikai to to kļūdas paziņojumu, ka trūkst templeites arguments. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
elvman Indago Uzvarētājs
![Indago Uzvarētājs Indago Uzvarētājs](https://forums.gamedev.lv/images/ranks/cup1.gif)
Joined: 09 Apr 2003 Posts: 1278 Location: Kuldiga
|
Posted: Sat Feb 09, 2008 5:29 pm Post subject: |
|
Beidzot dabūju nokompilēties:
Code: |
class BaseFunctionHandler
{
public:
BaseFunctionHandler();
virtual ~BaseFunctionHandler();
virtual void Execute(Message* message, User* sender) = 0;
};
template <class T> class MemberFunctionHandler: public BaseFunctionHandler
{
public:
typedef void (T::*MemberFunction)(Message*, User*);
MemberFunctionHandler(T* object, MemberFunction memberFunction):
mObject(object), mFunction(memberFunction)
{
}
void Execute(Message* message, User* sender)
{
(mObject->*mFunction)(message, sender);
}
private:
T* mObject;
MemberFunction mFunction;
};
class MessageHandler
{
public:
MessageHandler()
{
}
virtual ~MessageHandler()
{
}
void HandleMessage(Message* message, User* sender)
{
std::map<uint8,BaseFunctionHandler*>::iterator i = mHandlers.find(message->GetType());
if(i != mHandlers.end())
i->second->Execute(message, sender);
}
template <class T> void RegisterEventFunc(uint8 messageType, T* object, void (T::*memberFunction)(Message*, User*))
{
mHandlers[messageType]= new MemberFunctionHandler(object, memberFunction);
}
private:
std::map<uint8,BaseFunctionHandler*> mHandlers;
}; |
_________________ long time; /* know C */ |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
elvman Indago Uzvarētājs
![Indago Uzvarētājs Indago Uzvarētājs](https://forums.gamedev.lv/images/ranks/cup1.gif)
Joined: 09 Apr 2003 Posts: 1278 Location: Kuldiga
|
Posted: Sat Feb 09, 2008 5:48 pm Post subject: |
|
Tagad, kad esmu nokompilējis kodu, varu droši izmantot fastdelegate. Man viņš bija jānokompilē vienkārši principa pēc (nepatīk zaudēt, itsevišķi, datoram) _________________ long time; /* know C */ |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|