c++ - 在 Xcode : error during compilation: STL vector 中编译 C++ 类

标签 c++ xcode porting

我有一个 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/

相关文章:

c++ - 是否有可能实现一个可以容纳 POD 元素并在编译时初始化分配的静态存储的容器?

c++ - 在 argv[] 开头添加参数

iphone - 在 iPhone 应用程序中添加字体

c# - 有人能告诉我这个疯狂的 C++ 语句在 C# 中意味着什么吗?

c++ - 无法从 'const wchar_t *' 转换为 '_TCHAR *'

c++ - CUDA 设备代码中的 constexpr 数组

c++ - 继承和CRTP

xcode - Swift NSTimer 编码

ios - ScrollView swift 3 中的垂直对齐图像

visual-studio - Visual Studio 中的 yacc 和 Bison