////////////////////////
/////counter.h file/////
////////////////////////
#ifndef _COUNTER_H
#define _COUNTER_H
class Counter{
private:
int counter;
int limit;
static int nCounters;
public:
Counter(int arg, int arg);
void increment();
void decrement();
int getValue();
static int getNCounters();
};
#include "counter.cpp"
#endif
//////////////////////////
/////counter.cpp file/////
//////////////////////////
#include <string>
#include "counter.h"
Counter::Counter(int a, int b){
counter=a;
limit=b;
if (&nCounters==NULL){
nCounters=0;
}
nCounters++;
}
void Counter::increment()
{
if (counter<limit) counter++;
}
void Counter::decrement()
{
if(counter>0) counter--;
}
int Counter::getValue(){
return counter;
}
int Counter::getNCounters(){
int dummy=nCounters;
return dummy;
}
I'm getting a linker error every time I try to access nCounters.
so i get this result when compiling:
[Linker error] undefined reference to `Counter::nCounters'
[Linker error] undefined reference to `Counter::nCounters'
[Linker error] undefined reference to `Counter::nCounters'
ld returned 1 exit status