• 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
Re: Accessing C++ class method from ObjC++ code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing C++ class method from ObjC++ code


  • Subject: Re: Accessing C++ class method from ObjC++ code
  • From: Jonathan Prescptt <email@hidden>
  • Date: Mon, 19 Nov 2007 20:21:35 -0500

Charles:

What you have defined is a "member" function.  That is, you can't write

	Vision::analyze(...);

in your user code, you have to instantiate an instance of the class
before you can use it, i.e.,

	Vison vis;
	vis.analyze(...);

or

	Vision* vis = new Vision();
	vis->analyze(...);

If it is really a "class" member function as in Obj-C or Java, you have
to preface the definition with the keyword "static,"  like:

class Vision
{
   public:

	static void analyze(...);
};

Now you can call Vision::analyze(...);

The keyword "static" makes the function available without requiring an
instance of the class.  However, if you think about it, the
"class" (static) function can only manipulate any static member data in
the class (invocation of function may be done without having ANY
instances of the class instantiated, so no instance member data would be
available).

Jonathan

On Sun, 2007-11-18 at 12:21 -0500, Charles Hamel wrote:
> Hi
>
> I have a C++ class definition in a file that looks like this:
>
> class Vision {
>
> 	public: void analyze(NSMutableArray* a);
>
> };
>
> The implementation of this class in located in a seperate file (.mm
> extension) and compiled as Obj-C++ code.
>
> I have an AppController ObjC class that has as an instance variable of
> pointer to a Vision object. The AppController.mm file is also compiled
> as Obj-C++. AppController.mm imports AppController.h which in turns
> imports Vision.h.
>
> In one of AppController's method, I call this : vision-
>  >analyze(newArray);
>
> Everything compiles fine, except linker says :
>
>    "Vision::analyze(NSMutableArray*)", referenced from:
>        -[AppController testAction:] in AppController.o
> ld: symbol(s) not found
> collect2: ld returned 1 exit status
>
> I have tried to specify the symbol visibility using
> __attribute__((visibility("default"))) but that failed as well.
>
> What am I missing ?
>
> Thank you
>
> Charles
>
> e
>
>
>
>
> _______________________________________________
>
> 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

_______________________________________________

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

References: 
 >Accessing C++ class method from ObjC++ code (From: Charles Hamel <email@hidden>)

  • Prev by Date: Re: error converting HTML into an attributed string
  • Next by Date: physics engine?
  • Previous by thread: Re: Accessing C++ class method from ObjC++ code
  • Next by thread: NSFileManager destroying target of symlink at changefileattributes
  • Index(es):
    • Date
    • Thread