June 19, 2010
MarkBernstein.org
 
Follow me on Twitter

Objective C and C++

OK: I’ve got an Objective C++ issue. It’s easy unless you don’t know that answer. And I don’t.

I’ve got a complex C++ object:

class Hyperext {....}

And I want to have a pointer to one of these objects as an instance variable in an Objective C controller:

HypertextView.h
@interface HypertextView :UIView {
  Hypertext *	hypertext;
...
}

How do I do this without making HypertextView and everything that touches HypertextView. an Objective C++ file?

In C++, I use a Hypertext* as an instance variable and forward-declare that Hypertext is a class. The means HypertextView doesn't depend on Hypertext.h, which is a very good thing. How do I manage the same sort of dependency firewall in ObjectiveC++?

That is, how do I build an interface between the C++ model and the Objective C view without making the entire view and controller hierarchies requires Objective C++?

Or am I being excessively scrupulous?