我想知道这里出了什么问题:
class Grasp
{
typedef struct
{
int unique;
int intersection;
int sets;
float alpha;
int *covered;
int *choosen;
}best;
static best findSolution();
}
开.cpp:
best Grasp::findSolution()
{
//it doesn't matter
}
该行有错误:最佳 Grasp :: findSolution()
'最佳'未命名类型
为什么?
答案 0 :(得分:8)
best
是嵌套类型,因为它是Grasp
的成员。因此,您需要将返回类型限定为:
Grasp::best Grasp::findSolution()
{
//your code
}
请注意返回类型。 : - )
答案 1 :(得分:0)
best
是Grasp
中包含的typedef。除非它是全局的,否则编译器无法知道它属于该类。请改用Grasp::best
:
Grasp::best Grasp::findSolution()
{
// ..
}