#ifndef _MY_OPENCLPLATFORM_
#define _MY_OPENCLPLATFORM_
#include "OpenCL.h"
namespace my
{
class OpenCLPlatform
{
cl_platform_id mplatformID;
cl_uint mnumDevices;
std::vector<OpenCLDevice> mdevices; // OpenCLDevice was not declared in this scope
public:
OpenCLPlatform(cl_platform_id platformID);
void getDevices();
void printInfo();
cl_platform_id& getPlatformID();
};
}
#endif
#ifndef _MY_OPENCLDEVICE_
#define _MY_OPENCLDEVICE_
#include "OpenCL.h"
namespace my
{
class OpenCLDevice
{
cl_device_id mdeviceID;
public:
OpenCLDevice(cl_device_id device);
void printInfo();
void printDeviceType(cl_device_type deviceType);
};
}
#endif
#ifndef _MY_OPENCL_
#define _MY_OPENCL_
#if defined(__APPLE__) || defined(MACOSX)
#include <OpenCL/opencl.h> // This works only for XCODE compiler
#else
#include <CL/cl.h>
#endif
#include <cassert>
#include <iostream>
#include <vector>
#include "Exception.h"
#include "OpenCLDevice.h"
#include "OpenCLPlatform.h"
namespace my {
class OpenCLDevice;
class OpenCLPlatform;
class OpenCL;
class OpenCL
{
cl_uint mnumPlatforms;
std::vector<OpenCLPlatform> mplatforms;
void getPlatforms();
public:
OpenCL();
~OpenCL();
void quickSetup();
void printPlatformVersions();
};
}
#endif
是否排序“类 OpenCLDevice;类 OpenCLPlatform;类 OpenCL;” 事情?有时,头文件相互依赖,这可能导致“难以理解”或复杂的包含...您是否有一种“单向”技术来处理您一直使用的复杂的包含?
编辑:
我更改了代码以匹配我的实际问题。如果您查看上面的代码,编译器会说“OpenCLDevice 未在此范围内声明”。
编辑:
我终于让代码工作了,这就是我所做的: 1. 在 OpenCLPlatform.h 中添加 #include "OpenCLDevice.h" 2. 编译 3. 在 OpenCLPlatform.h 中删除 #include "OpenCLDevice.h" 4. 编译它现在工作!
编辑:
我清理了项目并删除了所有依赖项,但我又遇到了同样的错误。
编辑:
我认为编译器对代码做了一些事情。它可能选择不包含头文件和源文件中未使用但在其他头文件和源代码中使用的库