• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to force a message to a overriding method from within an init method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: How to force a message to a overriding method from within an init method
      • From: Andreas Grosam <email@hidden>
    • Re: How to force a message to a overriding method from within an init method
      • From: Graham Cox <email@hidden>
    • Re: How to force a message to a overriding method from within an init method
      • From: Shawn Erickson <email@hidden>
  • Prev by Date: Re: Application Architecture or approach
  • Next by Date: Re: Application Architecture or approach
  • Previous by thread: Re: Application Architecture or approach
  • Next by thread: Re: How to force a message to a overriding method from within an init method
  • Index(es):
    • Date
    • Thread