Re: using C++ class in the Obj-C file (FAILED...)
Re: using C++ class in the Obj-C file (FAILED...)
- Subject: Re: using C++ class in the Obj-C file (FAILED...)
- From: Brady Duga <email@hidden>
- Date: Wed, 20 Feb 2008 11:45:25 -0800
On Feb 17, 2008, at 3:49 AM, Leopard x86 wrote:
The include method is forbidden, for if I included the foo.h, the
previous files included by foo.h throwed out lots lots of compile
error. Very horrible...
It might make the most sense to figure out what those problems are and
fix them. Often it is a simple matter of needing to include another
file first.
Then I want to use a trick to solve this: because the UNIX library
has been compiled into a dylib file, I can use the C++ keyword
"extern" to let the compiler think the class has been defined. When
the code compiled, the compiler will automatically find the symbol
defined in the dylib file and solved the linker.
Hmm... I'm not sure you understand what extern is for.
extern "C" {
class foo;
};
Basically, this code tells the compiler to handle the linkage to
functions and variables in the brackets as though the current language
is C instead of C++. Of course, there are no functions or variables in
those brackets, just a forward declaration of a class. You can drop
the extern "C" and just forward declare class foo, but that probably
won't help. If all you ever do in your code is pass the pointer around
(you never call 'new foo' or access any of the classes members) then
it might be ok. However, if you actually need to *use* an object of
class foo, you need the full definition of the class.
Of course, this is a very non-Cocoa-ish question. Heck, I doubt it is
even related to Objective-C[++]. You might want to take further
questions to a more appropriate place (and no, I don't know where that
place is - perhaps someone else can recommend a list).
--Brady
_______________________________________________
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