我无法将此 C++ 源代码转换为 Objective C。我有一个类假设将新行号插入到单词列表中,如果行号已经打开,那么它只会返回,在我使用的 C++ 代码中向量方法 insert 将行插入 lineNumbers 数组,但我似乎无法替代目标 c。这是我的 C++ 代码
/*Constructor. */
UniqueWord::UniqueWord(const string word, const int line)
{
wordCatalog=word;
count = 0;
addLine(line);
}
//Deconstructor.
UniqueWord::~UniqueWord(void)
{
}
/* Adds a line number to the word's list, in sorted order.
If the number already exists, it is not added again.
*/
void UniqueWord::addLine(const int line){
int index = newIndex(line);
++count;
if (index == -1)
return;
LineNumbers.insert(LineNumbers.begin() + index, line);//here i'm trying to figure out my substitute
}
这就是我迄今为止在Objective C中得到的:
@implementation UniqueWord
-(id)initWithString:(NSString*)str andline:(NSInteger)line{
_wordCatalog=str;
count=0;
//i could not find a substitute for addline(line) here
//what do i return as an id by the way?
}
-(void) addLine:(const int)line{
int index=newIndex(line);
++count;
if(index==-1)
return;
[ _LineNumbers //I dont' know what to add here
}