I´m trying to use a specified class in another one declaring it like static parameter. The first class is the DNI or NID(in English) class and the second one is the counter. The program has to count the iterations which takes to sort an array with different sorting algorithms. So every comparison in the DNI class the counter has to increment.
The problem is that the compiler complains about unidefined symbol... The err message: Undefined symbols for architecture x86_64:
"DNI::counter", referenced from:
DNI::operator>(DNI const&) in main-3713cf.o
DNI::operator>=(DNI const&) in main-3713cf.o
It only complains in two of the operators, and I dont know why.
DNI class:
#pragma once
#include <cstdlib>
#include <ctime>
#include "../Counter.hpp"
class DNI
{
private:
unsigned int num;
public:
static Counter counter;
DNI() {
num = 30000000 + (rand() % 50000000);
};
DNI(int i): num(i) {};
virtual ~DNI() {};
operator int() const { return num;};
bool operator==(const DNI & dni) {
counter++;
return dni.num == num;
};
bool operator<(const DNI & dni) {
counter++;
return num < dni.num;
};
bool operator>(const DNI & dni) {
counter++; // ERR HERE
return num > dni.num;
};
bool operator<=(const DNI & dni) {
counter++;
return num <= dni.num;
};
bool operator>=(const DNI & dni) {
counter++; // ERR HERE
return num >= dni.num;
};
};
Counter class:
#pragma once
#include <limits>
class Counter
{
private:
int accum;
int max;
int min;
int localAccum;
public:
Counter(){
reset();
};
void start() {
localAccum = 0;
};
int stop() {
min = localAccum < min ? localAccum:min;
max = localAccum > max ? localAccum:max;
accum += localAccum;
return localAccum;
};
void reset(void) {
min = std::numeric_limits<int>::max();
max = 0;
accum = 0;
};
Counter& operator++(int) {
localAccum++;
return *this;
};
int getAccum() { return accum; };
int getMax() { return max; };
int getMin() { return min; };
};
Any idea why its only complaining only in those two?? Thank you!
Aucun commentaire:
Enregistrer un commentaire