Re: Mixing C++ with Objective C
Re: Mixing C++ with Objective C
- Subject: Re: Mixing C++ with Objective C
- From: Justin Kolb <email@hidden>
- Date: Wed, 3 Aug 2005 07:54:55 -0500
Whenever a C++ class is declared not using a pointer it must initialize
the class using the no argument constructor or a constructor in which
every argument has a default value (if I remember correctly).
So
Class2 *class2; // would work
but
Class2 class2; // is not going to work as this class doesn't have a no
argument constructor
I'm not a C++ expert so I'm not sure if it's valid to pass arguments
like you listed (but you could try it though):
Class2 class2(i, j);
Otherwise you are stuck doing this in the Objective-C constructor which
is more Objective-C like anyway:
class2 = new Class2(i, j);
On Aug 3, 2005, at 1:21 AM, John Draper wrote:
I tried to post this last week. Got no response from it, nor did I see
it appear in
the list. If you hav gotten this before, I apologize... but I urgently
need
answers to this question.
This came from:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/
index.html
Note code below....
#import <Cocoa/Cocoa.h>
struct Class0 { void foo(); };
struct Class1 { virtual void foo(); };
struct Class2 { Class2(int i, int j); };
@interface Foo : NSObject {
Class0 class0; // OK <---- Is this OK because there was no constructor?
Class1 class1; // ERROR!
Class1 *ptr; // OKācall 'ptr = new Class1()' from Foo' init,
// 'delete ptr' from Foo's dealloc
Class2 class2; // WARNING - constructor not called!
...
@end
OK, but I don't see why Class2's constructor is not called. Is that
because it
didn't include the arguments... IE:
Class2 class2(i, j); // WOULD this work?
John
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden