static方法不能返回struct类型?(C ++)

时间:2013-07-15 18:18:13

标签: c++ methods static struct return

我想知道这里出了什么问题:

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()

'最佳'未命名类型

为什么?

2 个答案:

答案 0 :(得分:8)

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

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

请注意返回类型。 : - )

答案 1 :(得分:0)

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

Grasp::best Grasp::findSolution()
{
    // ..
}
相关问题