Re: using a virtual C++ function
Re: using a virtual C++ function
- Subject: Re: using a virtual C++ function
- From: "Florian G\. Pflug" <email@hidden>
- Date: Tue, 10 Jun 2003 10:13:17 +0200
On Mon, Jun 09, 2003 at 04:48:35PM -0400, Robert Palmer Jr wrote:
>
I have a C++ class with a virtual function that is expected to be
>
overridden.
>
>
class SensorFinder
>
{
>
public:
>
SensorFinder();
>
virtual ~SensorFinder();
>
>
void search();
>
virtual void sensorFound(char hwAddr[6]){};
>
}
>
class ObjCSensorFinder
{
public:
SensorFinder(id _delegate);
:SensorFinder::SensorFinder()
:delegate(_delegate)
{
[delegate retain] ;
}
virtual ~SensorFinder()
{
[delegate release] ;
}
virtual void sensorFound(char hwAddr[6])
{
[delegate foundSensor: hwAddr] ;
}
protected:
id delegate ;
}
Then write a ObjC Class for storing lists of sensors, and manipulating them
(conceptually, this class would be part of the controller of your app).
The controller should have an instance of ObjcSensorFinder as a instance
variable, (of course initializing ObjcSensorFinder with self as delegate),
and call myfinder.search() when it needs to update the list of sensors.
If course ObjcSensorFinder could add entries to an NSMutableArray or
NSDictionary directly, but I believe using an informal interface here
decouples those two parts far better.
greetings, Florian Pflug
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.