• 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: Obj-C++ Tuturial Anywhere?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obj-C++ Tuturial Anywhere?


  • Subject: Re: Obj-C++ Tuturial Anywhere?
  • From: "Dennis C. De Mars" <email@hidden>
  • Date: Wed, 15 Aug 2001 23:19:07 -0000

Andreas Monitzer <email@hidden> said:

> On Thursday, August 16, 2001, at 12:03 , Todd Blanchard wrote:
>
> > 5) The only other good use might be the following "smart releasing
> > pointer"
> > class:
> >
> > class Id
> > {
> > id _object;
> > Id(id obj) : _object([obj retain]) {}
> > ~Id() { [_object release]; }
> > operator id() { return _object; }
> > }
> >
> > ...
> > {
> > Id foo = [MyClass newObject];
> >
> > } // destructor releases foo
> >
> > This might not work though - I haven't tried it as I don't have the new
> > thingy.
>
> Correct C++ is:
>
> Id foo([MyClass newObject]);

No, actually his statement is a legal alternative syntax. That is to say, if you have a
constructor:

TheClass::TheClass(X arg);

then declaring a variable of class TheClass, you can write

TheClass var(arg);

or

TheClass var = arg;

This only works if the constructor does not have more than one required
argument, otherwise you have to use the first syntax.

However, I think this class might not work if [MyClass newObject] has a return
type other then id; although Objective C statements recognize that any Objective
C class can be cast to "id", I am guessing the the C++ function overloading logic
would not recognize this. Of course, this discussion is pretty academic, I don't
think many people are going to be interested in doing this sort of thing...

Dennis D.


References: 
 >Re: Obj-C++ Tuturial Anywhere? (From: Andreas Monitzer <email@hidden>)

  • Prev by Date: Re: Fun with NSRunLoop <solved>
  • Next by Date: Re: NSImage in NSTableView looks like poop
  • Previous by thread: Re: Obj-C++ Tuturial Anywhere?
  • Next by thread: Select All the rows of a column of browser
  • Index(es):
    • Date
    • Thread