C++ 包含的类不被另一个类识别

标签 c++ class include

我正在尝试使用 C++ 进行引导。我有一个执行采样计算的 Bootstrapping 类,一个存储结果的 Sample 类:

Sample.h文件中

class Sample
{
      // do something
};

Bootstrapping 类中

#include <vector>
using namespace std;

class Bootstrapping
{
 private:
    vector<Sample> sample_list;    // Here the problem happens

   // do something
};

main.cpp文件中

#include <iostream>
#include "Bootstrapping.h"
#include "Sample.h"
using namespace std;

int main()
{
    // do something
}

当我调试上面的代码时,编译器在 Bootstrapping 类中弹出错误,提示 identifier "Sample"is undefined。但是我显然已经将它包含在 main 中了!

谁能帮我解决这个问题?非常感谢。

最佳答案

您需要在 Bootstrapping.h 文件中#include "Sample.h"

关于C++ 包含的类不被另一个类识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18469913/

相关文章:

Python - 返回所有被方法修改的 self.* 变量

java - 类加载器返回 NoSuchMethodException 错误

linux - Windows7 中的 OpenCV 和 CMake : wrong include dir

include - 检查javascript lib是否已经存在

c++ - 为什么主函数不能将正确的参数传递给 pthread_creat 函数

c++ - 如何使用模板函数调用 Functor 模板类

c++ - 检查QT输入的输入

c++ - 组织 C++ 套接字服务器的最佳方式是什么?

Swift 创建字典 Int : Class_Type

php - 包含在变量内 - 包含但不打印变量