Re: reusing an object
From: Jacob Jensen (jacob_news_dkNoSpaaaammmm_at_yahoo.co.uk)
Date: 03/04/04
- Next message: Peter Ammon: "Re: Optimizing a switch statement"
- Previous message: David Kastrup: "Re: off-topic: Why is lisp so weird?"
- In reply to: Gil: "reusing an object"
- Next in thread: Rolf Magnus: "Re: reusing an object"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 4 Mar 2004 13:05:52 +0100
I would create a function SetDefault() in SomeObject that sets all the
values to their defaults.
You cannot do
> // I would now like a clean so1
> // can I do this?
>
> so1 = new SomeObject();
o you cannot do this, since new SomeObject() creates a new object in memory
and returns a pointer to it, and so1 is not a pointer to a SomeObject.
You could do what you want to do by declaring pointers to SomObject as such
SomeObject* pso1;
pso1 = new SomeObject(); // memory is allocated dynamically and is pointed
at by pso1
pso1->setvalue1(1);
pso1->setvalue2(1);
// If you want a new "clean" object, simply delete the one created, and
create a new one
delete pso1; // If this is omitted, you would have garbage = memory not
pointed to by anyone
pso1 = new SomeObject(); // a new object is created in memory and is pointed
at by pso1
- Next message: Peter Ammon: "Re: Optimizing a switch statement"
- Previous message: David Kastrup: "Re: off-topic: Why is lisp so weird?"
- In reply to: Gil: "reusing an object"
- Next in thread: Rolf Magnus: "Re: reusing an object"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|