• 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
Bugs with Obj-C++ compiler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bugs with Obj-C++ compiler


  • Subject: Bugs with Obj-C++ compiler
  • From: email@hidden
  • Date: Mon, 12 Nov 2001 10:57:01 +0100

There is a lot of bugs in the Obj-C++ compiler (in particular it crashes frequently; sometimes PB crashes with him, too). I don't bother to sent each of them to Apple, but I would like to have advices on this one, because it is particularly strange, as it expresses a subtle difference with the Obj-C compiler:

I have a C++ struct named Point3D (which is basically three floats with a few inline methods), an Objective-C protocol

@protocol Positionnable
-(Point3D)center;
.....
@end

and in another class, a call like:

id<Positionnable> item = newSelection;
[centerControl setCoordinatesValue:(Point3D)[item center]];

(Note the cast; I tried to help the compiler). TO ME it looks like valid code, and the Obj-C compiler accepts it without even any warning (in that case Point3D appears as a simple struct, though). Now if only I rename the same file with ".mm" instead of ".m", I get a lot of errors (not only here!
) starting with:

CCCObjectPositionController.mm:38: warning: multiple declarations for method `center'
CCCObjectPositionController.mm: In function `':
/System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:241: warning: using `-(void)center'
CCCObjectPositionController.mm: In function `':
Positionnable.h:35: warning: also found `-(struct Point3D)center'
CCCObjectPositionController.mm: In function `':
Positionnable.h:17: warning: also found `-(struct Point3D)center'
CCCObjectPositionController.mm:38: invalid use of void expression

So the OBj-C++ compiler is confused by another method (from NSWindow) which is completely non-related to my one. Then it CHOOSES THE WRONG ONE, and ends with an error (last line)! So I can't even ignore that...

After a lot of tries, I finally found a way to overcome that:

NSObject<Positionnable>* item = newSelection; // instead of id

does the trick.

Hope this information will be useful to other people with similar difficulties. Note that I still don't understand the rationale behind, so if anyone has an explanation, thanks in advance.

Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.


  • Follow-Ups:
    • Re: Bugs with Obj-C++ compiler
      • From: Stéphane Sudre <email@hidden>
  • Prev by Date: Re: New Cocoa Programmer
  • Next by Date: Why does TableView not respond to it's inherits methods?
  • Previous by thread: Re: Preference Pane Sample Not quite working
  • Next by thread: Re: Bugs with Obj-C++ compiler
  • Index(es):
    • Date
    • Thread