Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

how declare global variable?

$
0
0

How do I declare a global variable in C++ ?  I thought I declared the variable as static in the .cpp file and then declared the definition of that variable in the .h file.  But I get a C2086 - redefinition.

// the Train2a.cpp file

#include "stdafx.h"
#include "Train2a.h"

namespace steve {
int GlobalCounter = 25 ;
}
// the Train2a.h file

#pragma once
#include "stdafx.h"

namespace steve {
static int GlobalCounter ;
}



Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>