Multiple Inheritance in Objective-C

Possible duplicate:
Objective-C multistragging inheritance

Hi,

Target C does not support multiple inheritance. I am transferring cpp code in Objective-C

How to declare this definition in Objective-C?

class A:protected B,protected C
{
  //stmts;
}

@interface A:protected B,protected C
{
}
@end

impossible.

+1
source share
2 answers

Objective-C does not support multiple inheritance, so this is not possible.

Inheritance is an "is-a" relationship, one class can have only one thing - a relationship through inheritance. You can have several relationships - through protocols (interfaces in Java or C # parlace or a fully abstract class in C ++).

is-a "has-a". has-a. , . :

@interface A : NSObject {
  @private
    B* _b;
    C* _c;
}
// ... stuff
@end

B C . , , B theAnswer, A :

-(int)theAnswer {
    return [_b theAnswer];
}

, , , .

+2

.

, ++.

Objective-C , ++, . , , NSArray, , , , NSArray " ".

, , NSArray. , forwardingTargetForSelector:, , , NSArray. , .

:

, , , NSArray, :

@interface MyClass : NSObject
{
@private
    NSArray* backingArray;
}

// declarations of your methods

@end

@implementation MyClass

// implementations for your methods + initialisation

-(id) forwardingTargetForSelector: (SEL) aSelector
{
    return backingArray;
}

@end

- categories. , "", -forwardingTargetForSelector: , , . , , PeyloW.

+3

Source: https://habr.com/ru/post/1755613/


All Articles