[Dev-C++] can I use virtual function here?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Lloyd <ll...@cd...> - 2007-12-06 13:11:54
|
Hi,
I want to write an extendable application where new classes can be
added with out modifying an existing code. Let me brief it with an
example. I am writing a network packet dissector. Each packet may
consist of so many protocols in a hierarchical manner. We will know the
protocol in level 'n' from the 'n-1' th level. Though there are hundreds
of protocols we must be able to add new protocols without modifying the
existing code.
So when we are on protocol at level 'n', it must be able to determine
the protocol at level 'n+1' and create the object. how can I do this?
my present implementation would be like this
func_proto(int ProtocolType)
{
switch(ProtocolType)
{
case IP:
DissectProto(IP);
case ARP:
DissectProto(ARP);
....
}
}
DissectProto(int type)
{
//Extract info from packet...
......
// Determine the type of protcol in the next level
....
//call func_proto with identified protocol type
func_proto(ProtocolType);
}
Here I would have to add new cases as we add new protocol dissectors,
Instead of that can I use any better way?
Thank you very much
Lloyd
______________________________________
Scanned and protected by Email scanner
|