将 std::vector 与结构一起使用时出现不完整的类型错误

Incomplete type error when using std::vector with structs

本文关键字:错误 类型 vector std 结构 一起      更新时间:2023-10-16

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

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

法典:

项目Handeler.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

弹丸手.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;
        }
    }
}

这编译得很好(在这里测试过: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()
{
}

请注意删除*、循环变量的正确类型和额外的类说明符。