In article <woody-34E181.16245304072008@[EMAIL PROTECTED]
>,
William Woody <woody@[EMAIL PROTECTED]
> wrote:
> In article <oster-06D6C8.20465203072008@[EMAIL PROTECTED]
>,
> David Phillip Oster <oster@[EMAIL PROTECTED]
> wrote:
>
> > In article <woody-33200E.17164003072008@[EMAIL PROTECTED]
>,
> > William Woody <woody@[EMAIL PROTECTED]
> wrote:
>
> > > Note that this implies that you either #include the C++ header in
your
> > > Objective C header, or you need to declare the CPPClass in the
Objective
> > > C header as a anonymous C++ class. In either case, this means you
can
> > > only #im****t your Objective C header in a .mm file.
> >
> > Not So! Remember that in C++ 'struct' is the same as 'class' except in
a
> > 'struct' all the members default to public. So, you can forward
declare
> > in your Obj-C.h file:
> >
> > typedef struct CPPClass CPPClass;
> >
> > this lets you include your .h file in a .c file just fine.
>
> True 'nuff; however, I always get nervous doing that because at some
> point the C++ compiler will see:
>
>
> typedef struct CPPClass CPPClass;
>
> ...
>
> class CPPClass {
> ...
> };
>
> My fear is that someday some compiler will ***** with the 'struct
> CPPClass'/'class CPPClass' mismatch. Semantically 'struct' == 'class'
> for now, but I've been bit in the past by similar issues where the
> semantics subtly changed over time.
>
>
> Call me conservative to the point of paranoid about such things... :-)
Don't do that! Of course that's an error. Leave the forward declare as
is, but say:
struct CPPClass {
public:
CPPClass();
... // other methods here.
};
Since, as I said, in C++ a struct is identical to a class, except for
the default visibility of its contents: struct defaults to public: and
class doesn't.
I'll call you conservative, but this is one part of C++ that is never
going to change, since it, like
#ifdef __cpplusplus
extern "C" {
#endif
....
#ifdef __cpplusplus
}
#endif
is a part of the language that exists for interoperability between C and
C++ , and the standards committee, and they won't break it.


|