使用带结构的std :: vector时不完整的类型错误

时间:2016-01-31 06:32:23

标签: c++ c++11 vector stl

我正在使用c ++ STL向量,并且有一个名为 projectileList的结构向量。我正在尝试迭代向量,在迭代时获取和设置struts中的值,但是我的代码拒绝编译,错误“不允许不完整类型。”

任何人都可以指出我做错了什么:

代码:

ProjectHandeler.h:

#include "stdafx.h"
#include "DataTypes.h"
#include <vector>

class ProjectileHandeler {

private:

    int activeObjects;

    std::vector<projectile> projectileList;

    void projectileUpdater();


public:
    ProjectileHandeler(projectile* input[], int projectileCount);

    ~ProjectileHandeler();

};

#endif

projectileHandeler.cpp

#include "stdafx.h"
#include "DataTypes.h"
#include "ProjectHandeler.h"
#include <vector> 

ProjectileHandeler::ProjectileHandeler(projectile* input[], int projectileCount)
{
    for (int i = 0; i < projectileCount; i++)
    {
        projectileList.push_back(*input[i]);
        activeObjects += 1;
    }

    //NO extra slots. Not that expensive.
    projectileList.resize(projectileList.size());
}

void ProjectileHandeler::projectileUpdater()
{
    while (true)
    {
        for (unsigned int i = 0; i < projectileList.size(); i++)
        {
            if (projectileList[i].isEditing == true)
                break;
        }
    }

}

1 个答案:

答案 0 :(得分:1)

这编译好(在此测试:http://codepad.org/cWn6MPJq):

#include <vector>

struct projectile {
    bool isEditing;

    };


class ProjectileHandeler {

private:
    std::vector<projectile> projectileList;

void projectileUpdater()
{
    //This bit loops to infinity and beyond! ...or at least untill the handeler is destroyed.
    while (true)
    {
        for (unsigned int i = 0; i < projectileList.size(); i++)
        {
            if (projectileList[i].isEditing == true) //Throws Incomplete type error
                break;
        }
    }

}
};

int main()
{
}

注意删除*,正确类型的循环变量以及删除额外的类说明符。