mardi 3 avril 2018

linking error : multiple definition of static variable

So I wrote the following code first and was getting a compile error. After reading this answer : static array class variable "multiple definition" C++ I modified my code and moved the static variable definition to a cpp file and it executes fine, but I'm unable to understand that when I have used pre-processor guards, why is it showing multiple definition error ?

#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;

Aucun commentaire:

Enregistrer un commentaire