NSMutableArray包装在C ++类中

时间:2011-12-21 08:04:35

标签: c++ objective-c ios qt objective-c++

我正在从Qt Cocos2d移植到iOS cocos2d,使用Objective-C ++作为最小努力的语言,现在我将NSMutableArray包装在C ++类中以便于移植,基本上这是我的类

QList.h

#ifndef QLIST_H
#define QLIST_H

#import <Foundation/Foundation.h>

class QList {
    NSMutableArray* List;

public:
    QList();
    ~QList();
    void append(id);
    id at (int i);
    int size();
    bool isEmpty();
    id takeLast();
    id last();
    void prepend(id);
    id takeAt(int i);
    id takeFirst();
    void clear();
};

#endif

QList.mm

#ifndef QLIST_MM
#define QLIST_MM

#import "QList.h"

QList::QList() {
    List = [[NSMutableArray alloc] init];
}
QList::~QList() {
    [List autorelease];
    List = nil;
}
void QList::append(id object) {
    [List addObject:object];
}

id QList::at(int i) {
    return [List objectAtIndex:i];
}

int QList::size() {
    return [List count];
}

bool QList::isEmpty() {
    if ([List count] == 0)
        return true;
    return false;
}

id QList::takeLast() {
    id temp = [List lastObject];
    [List removeLastObject];
    return temp;
}

id QList::last() {
    return [List lastObject];
}

void QList::prepend(id object) {
    [List insertObject:object atIndex:0];
}

id QList::takeAt(int i) {
    id temp = [List objectAtIndex:i];
    [List removeObjectAtIndex:i];
    return temp;
}

id QList::takeFirst() {
    return takeAt(0);
}

void QList::clear() {
    [List removeAllObjects];

}

#endif

我正在接收此行的EXC_BAD_SIGNAL

    return [List count];

任何人都可以帮助我,我非常感谢,提前谢谢:)

1 个答案:

答案 0 :(得分:0)

这没有问题,问题出在这一行

ai_unit.playerP = this;

我正在评论它,直到稍后我才能取消注释,它试图访问它:)谢谢!,如果您对此代码有建议,请告诉我:P