• 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: Embedding C++objects in Objective C++
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Embedding C++objects in Objective C++


  • Subject: Re: Embedding C++objects in Objective C++
  • From: Clark Cox <email@hidden>
  • Date: Fri, 31 Dec 2004 14:52:18 -0500

The two solutions that I've used in the past are:
1) Just change that member to a pointer; "new" it in -init, and
"delete" it in -dealloc.
2) Write a little templated wrapper class that has no constructor or
destructor, contains a buffer of bytes that is the appropriate size
for the contained class, and provide accessors, type conversion
operators, and functions to directly call the constructor/destructor.


On Thu, 30 Dec 2004 14:00:37 +0100, Tommy Nordgren
<email@hidden> wrote:
> Are there any way to make xcode generate warnings instead of errors,
> when compiling Objective C++ classes that embed C++ classes with
> virtual methods. What i want to do is code according to the following
> pattern (it works if the C++ class has userdefined constructors, but no
> virtual methods:
>
> class MyCPPClass {
>         int nn;
> public:
>         MyCPPClass():nn(n) {};
>
>         ~myCPPClass() {};
>
>         void print() const;
>
> protected:
>         virtual void printSelf() const;
> };
>
> @interface MyClass : NSObject
> {
>         MyCPPClass member;
> }
>
> - (void) print;
> @end
>
> @implementation MyClass
>
> - (id) init
> {
>         [super init];
>         new ((void *) &member) MyCPPClass(789); //Call constructor myself via
> placement new
>         return self;
> }
>
> - (void) dealloc
> {
>         member.~MyCPPClass(); //Explicit destructor call
>         [super dealloc];
> }
>
> - (void) print
> {
>         member.print();
> }
> @end
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Xcode-users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>


--
Clark S. Cox III
email@hidden
http://www.livejournal.com/users/clarkcox3/
http://homepage.mac.com/clarkcox3/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Embedding C++objects in Objective C++ (From: Tommy Nordgren <email@hidden>)

  • Prev by Date: Re: Using custom build rules
  • Next by Date: Re: Localizing Apps-Problem with Foreign chars
  • Previous by thread: Embedding C++objects in Objective C++
  • Next by thread: Using custom build rules
  • Index(es):
    • Date
    • Thread