是那个再次制作boggle模拟器的人!这次我遇到了一个问题,即出于语法原因,该函数被强制返回指向对象的指针。我想访问指针指向的对象的函数。我该怎么办呢?我的相关功能代码如下。
boggleNode * nextNode(int adj){
return adjacency[adj]; //For switching between nodes.
}
bool getUsed(){
return isUsed;
}
private:
boggleNode * adjacency[8];
char letter;
bool isUsed;
};
最后,这是包含上述函数的函数:
int sift(boggleNode bog, string word, string matcher){
int endofnodes;
string matchee;
if (bog.getData() == 'q')
matchee = matcher + bog.getData() + 'u';
else
matchee = matcher + bog.getData();
if (compare(word, matcher) == 0){
cout << word << endl;
return 5; //If it finds the word, escape the loop.
}
if (word.find(matcher) == 0){
bog.makeUsed();
for (int j = 0; j < 8; j++){
if (bog.nextNode(j) != NULL){
if ((bog.nextNode(j)).getUsed() == 0){
endofnodes = sift(bog.nextNode(j), word, matchee);
if (endofnodes == 5)
return endofnodes;
}
}
bog.reset();
return 0;
//If it doesn't find anything, move onto next adjacency.
/*any words share a common starting letter sequence with matcher*/
//Sift using an adjacent node, and add the old string to the new one.
}
}
}
我特别询问这一行:
if ((bog.nextNode(j)).getUsed() == 0)
当我尝试编译此代码时,我得到了#34;错误:请求会员
getUsed' in
(&amp; bog) - &gt; boggleNode :: nextNode(j)&#39;,这是非类的
输入`boggleNode *&#39; &#34;
非常感谢任何帮助。提前致谢!
答案 0 :(得分:1)
您应该使用->
代替.
:
if ((bog.nextNode(j))->getUsed() == 0)
这是简写,在这种情况下,用于:
if ((*(bog.nextNode(j))).getUsed() == 0)