【发布时间】:2018-09-12 23:11:21
【问题描述】:
所以我先写了下面的代码,却遇到了编译错误。阅读此答案后: static array class variable "multiple definition" C++ 我修改了我的代码并将静态变量定义移动到一个 cpp 文件中并且它执行得很好,但是我无法理解当我使用预处理器保护时,它为什么会显示多个定义错误?
#ifndef GRAPH_H
#define GRAPH_H
#include<iostream>
#include<vector>
using namespace std;
struct node{
int element=0;
static vector<bool> check;
node(){
if(check.size()<element+1)
check.resize(element+1);
}
};
vector<bool> node::check;
#endif
【问题讨论】:
标签: c++11 linker-errors static-variables