我在Visual Studio 17(2022)项目中收到了以下警告,我可以将其简化为以下内容:
test1.cpp
#include <atomic>
#include "test.h"
int main() {
Test::g_test = true;
}
test2.cpp
#include <atomic>
struct A {
std::atomic<bool> m_test = false;
};
#include "test.h"
void a() {
Test::g_test = true;
}
测试.h
#pragma once
struct Test {
static inline std::atomic<bool> g_test = false;
};
结果:
1>------ Build started: Project: ConsoleApplication1, Configuration: Release x64 ------
1>test1.cpp
1>test2.cpp
1>LINK : warning C4744: 'static struct std::atomic<bool> Test::g_test' has different type in 'c:\consoleapplication1\test2.cpp' and 'c:\consoleapplication1\test1.cpp': '__declspec(align(1)) struct (1 bytes)' and 'struct (1 bytes)'
我是否违反了某些C++规则?这是微软风险投资公司的错误吗?什么是最好的解决方案/解决方法?