我有一个 C++ 类,它可以在带有 gcc 的 Linux 上和在 visual studio 中的 widows 上正常编译。
boid.h:
#ifndef BOID_CLASS_HEADER_DEFINES_H
#define BOID_CLASS_HEADER_DEFINES_H
#include "defines.h"
class Boid {
public:
// Initialize the boid with random position, heading direction and color
Boid(float SceneRadius,float NormalVel);
.....
protected:
...
};
#endif
在 boid.cpp 中:
#include "Boid.h"
// Initialize the boid with random position, heading direction and color
Boid::Boid(float SceneRadius,float NormalVel)
{
....
}
但是,当我在 Xcode 中编译这段代码时出现以下错误:
Compiling Boid.h: "error: vector: No such file or directory"
有什么想法吗?我认为您可以使用 C/C++ 代码并在 Xcode 中毫无问题地编译它?
谢谢
编辑:添加了 defines.h(还添加了#endif 到示例,但那是在原始代码中)
编辑 2:在注释掉一些包含内容为空的内容后,我得到了一个不同的错误:上面的 vector 错误。
#ifndef BOID_NAV_DEFINES_H
#define BOID_NAV_DEFINES_H
#include <stdlib.h>
#include <vector>
#include "Vector3d.h"
#include "Point3d.h"
#include "win_layer.h"
#endif
最佳答案
您是否将 C++ header 包含在 .m 文件中?
.m 文件被视为带有 Objective-C 扩展名的 .c 文件。
.mm 文件被视为带有Objective-C 扩展名的.cpp 文件,然后称为Objective-C++
只需将任何 .m 文件重命名为 .mm,右键单击或按住 ctrl 单击并在 Xcode 中选择文件重命名。
关于c++ - 在 Xcode : error during compilation: STL vector 中编译 C++ 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/534861/