How to force a message to a overriding method from within an init method
How to force a message to a overriding method from within an init method
- Subject: How to force a message to a overriding method from within an init method
- From: João Varela <email@hidden>
- Date: Thu, 12 Feb 2009 01:31:56 +0000
Hi all
I am porting most of my C++ code into Objective C and at the moment I
have this problem:
In C++ to force a constructor to call a overriding method of a
subclass I used pure virtual functions defined in an abstract (super)
class.
An example:
class Foo
{
Foo();
virtual read( x, y ) = 0; // pure virtual
};
class Bar : public Foo
{
Bar();
virtual Read( x, y ); // implemented in the subclass
};
// Foo constructor
Foo::Foo()
{
Read( x, y ); // <-- this calls Bar::Read and not Foo::Read
// because the latter is pure virtual
}
I know that the closest thing to a pure virtual function in Objective
C is a formal protocol. My question is: can you implement such a
behavior in objective C with a formal protocol?
Related to this, what method gets called inside the init method of the
superclass: a) the superclass method? or b) the overriding method if
there is one?
Although this is not strict Cocoa code, I think this is the best place
to ask this kind of question. Sorry for the mild "OT-ness" of my
question.
TIA
JV
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden