Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Mac Programmer Help > Re: Objective-C...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 8 Topic 3791 of 3882
Post > Topic >>

Re: Objective-C++ Instance Variables

by David Phillip Oster <oster@[EMAIL PROTECTED] > Jul 4, 2008 at 07:48 PM

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.
 




 8 Posts in Topic:
Objective-C++ Instance Variables
Jason8 <jason.leach@[E  2008-07-03 00:11:05 
Re: Objective-C++ Instance Variables
Gregory Weston <uce@[E  2008-07-03 07:52:36 
Re: Objective-C++ Instance Variables
Jason8 <jason.leach@[E  2008-07-03 07:44:01 
Re: Objective-C++ Instance Variables
Gregory Weston <uce@[E  2008-07-03 12:31:13 
Re: Objective-C++ Instance Variables
William Woody <woody@[  2008-07-03 17:16:40 
Re: Objective-C++ Instance Variables
David Phillip Oster <o  2008-07-03 20:46:53 
Re: Objective-C++ Instance Variables
William Woody <woody@[  2008-07-04 16:24:53 
Re: Objective-C++ Instance Variables
David Phillip Oster <o  2008-07-04 19:48:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 11:06:12 CST 2008.