|
|
User login
Feeds |
linked list
|
|||||
| Mon, 2004-12-20 23:38 | |
|
Hi Everyone
I have used the command pattern design and put all the different command object in a linked list type TSglQue<TCmd(interface)>, but when I extract a command object and call its execute funktion then everything closes down... It works if I only have one type of object in the linked list and the linked list template is of that type TSglQue<TSomeCmd(concrete command)>, ... it seem to me that TSglQue cannot handle different types of objects...? the thing is that I would like to have a linked list of different commands which I can iterate and execute..? Thanks in advance Christian |
|
Forum posts: 20
but here it goes:
I would like to have a linked list TSglQue<ClassInterface> where the
interface is an abstract class with on virtuel functions.
I would then like the list to contain different child classes of ClassInterface
ex.
ClassInterfaceChild1 -> ClassInterfaceChild2 -> ClassInterfaceChild1
thanks in advance
Forum posts: 2029
This is required for TSglQue to work (and in that sense, your interface class cannot be an abstract class as it needs to have this data member).
Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant
Forum posts: 20
class TCmd : public CBase
{
public:
virtual void Execute(CArrangementEngine *engine) = 0;
private:
TSglQueLink iLink;
};
class TCmdMakeNewArrangement : public TCmd
{
public:
void Execute(CArrangementEngine *engine);
TSglQue<TDeltager> qContacts;
TSglQue<TTidsInterval> qTimeintervalsAppointment;
TTimeIntervalMinutes timAppointmentLength;
};
This works... where the TSglQue<TCmdMakeNewArrangement>
TCmdMakeNewArrangement* arr = new(ELeave) TCmdMakeNewArrangement;
arr->Execute(iArrangementEngine);
But when TSglQue<TCmd> it doesn't work
TCmdMakeNewArrangement* arr = new(ELeave) TCmdMakeNewArrangement;
iArrangementEngine->AddCommand(arr);
void CArrangementEngine::AddCommand(TCmd *aCommandTask)
{
iCommandTasks.AddLast(*aCommandTask);
}
if(!iCommandTasks.IsEmpty())
{
TCmd *command = iCommandTasks.First();
command->Execute(this); here it goes wrong
iCommandTasks.Remove(*command);
delete command;
}
Forum posts: 20
> Sander van der Wal wrote:
> What's missing here is the call that constructs the iArrangementEngine
> object. If not properly constructed, the linked list will not be properly
> linkied.
>
>
> --
Im sorry to say that this isn't the problem... I didn't include the code
which
initializes the the iArrangementEngine. And I have tried the exact same code
where I instead of using the interface TCmd like this TSglQue<TCmd>
uses the concrete class TCmdMakeNewArrangement like this
TSglQue<TCmdMakeNewArrangement> where it works.
the code that works - TSglQue<TCmdMakeNewArrangement>:
TCmdMakeNewArrangement *command = iCommandTasks.First();
command->Execute(this);
iCommandTasks.Remove(*command);
before which doesn't work - TSglQue<TCmd>:
TCmd *command = iCommandTasks.First();
command->Execute(this); <-- fails
iCommandTasks.Remove(*command);
I wonder if u have to calculate the pointer TSglQueLink iLink in the
constructor for every class when u use an abstract class, because of
the different sizes for the different child object which the class holds?
Forum posts: 2029
constructor for every class when u use an abstract class, because of
the different sizes for the different child object which the class holds?
I am afraid that this value might need to be of fixed size (not sure however)
Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant