我有一个文件“ example.h,其中包含3个不同文件所需的全局变量,它看起来像这样:
#include <iostream>
using namespace std
#pragma once
int a;
float b;
someclass c;
但是如果被多次包含,它将返回编译器错误
“ a”的多个定义
“ b”的多个定义
“ c”的多个定义
我只想说我使用的是非常不可靠的编译器,例如,如果使用关键字“ inline”,则代码不会没有错误地运行。
编辑:
#ifndef IDONTKNOWWHATTOCALLTHIS
#define IDONTKNOWWHATTOCALLTHIS
#include <iostream>
using namespace std;
int a;
float b;
someclass c;
#endif
相同错误