C++ 将宏视为 class
C++ treats macro as a class
在 visual studio 中,我将配置类型设置为 .dll 而不是 .exe,因此有时我需要使用 __declspec(dllexport)
或 __declspec(dllimport)
。所以我在名为“Core”的头文件中为它们创建了宏
#pragma once
#ifdef B5_PLATFORM_WINDOWS
#ifdef B5_BUILD_DLL
#define B5_API __declspec(dllexport)
#else
#define B5_API __declspec(dllimport)
#endif // B5_BUILD_DLL
#else
#error Bos5 only supports Windows!
#endif // B5_PLATFORM_WINDOWS
我的命名空间“Bos5”中有一个 class“应用程序”,它使用 BS_API
#pragma once
#include "Core.h"
namespace Bos5 {
class B5_API Application
{
public:
Application();
~Application();
void Run();
};
}
在这个项目中一切正常,但是当我出于某种原因将其引用到另一个项目时 visual studio 认为 B5_API 是 class 而“应用程序”不是。因此下面的代码不会编译说命名空间 Bos5 没有结构或 class 称为“应用程序”
#include <FinalBos5.h>
class Sandbox : public Bos5::Application
{
public:
Sandbox(){}
~Sandbox(){}
};
int main() {
}
我觉得这张图更能说明我在说什么
好的,我已经解决了。原来问题是完全不同的事情。我的预处理器没有保存一些定义,所以在第二个项目中 B5_API 没有被定义
在 visual studio 中,我将配置类型设置为 .dll 而不是 .exe,因此有时我需要使用 __declspec(dllexport)
或 __declspec(dllimport)
。所以我在名为“Core”的头文件中为它们创建了宏
#pragma once
#ifdef B5_PLATFORM_WINDOWS
#ifdef B5_BUILD_DLL
#define B5_API __declspec(dllexport)
#else
#define B5_API __declspec(dllimport)
#endif // B5_BUILD_DLL
#else
#error Bos5 only supports Windows!
#endif // B5_PLATFORM_WINDOWS
我的命名空间“Bos5”中有一个 class“应用程序”,它使用 BS_API
#pragma once
#include "Core.h"
namespace Bos5 {
class B5_API Application
{
public:
Application();
~Application();
void Run();
};
}
在这个项目中一切正常,但是当我出于某种原因将其引用到另一个项目时 visual studio 认为 B5_API 是 class 而“应用程序”不是。因此下面的代码不会编译说命名空间 Bos5 没有结构或 class 称为“应用程序”
#include <FinalBos5.h>
class Sandbox : public Bos5::Application
{
public:
Sandbox(){}
~Sandbox(){}
};
int main() {
}
我觉得这张图更能说明我在说什么
好的,我已经解决了。原来问题是完全不同的事情。我的预处理器没有保存一些定义,所以在第二个项目中 B5_API 没有被定义