2

我想知道这里做错了什么:

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
}

该行有一个错误:best Grasp::findSolution()

' best ' 没有命名类型

为什么?

4

2 回答 2

8

best嵌套类型,因为它. Grasp因此,您需要将返回类型限定为:

Grasp::best Grasp::findSolution()
{
     //your code
}

注意返回类型。:-)

于 2013-07-15T18:20:31.780 回答
0

best是包含在Grasp. 除非它是全局的,否则编译器无法知道它属于该类。改用Grasp::best

Grasp::best Grasp::findSolution()
{
    // ..
}
于 2013-07-15T18:21:07.117 回答