C_CPP/11_PUTT/CopyOnWrite/LargeCowMatrix.cpp

49 lines
1.2 KiB
C++
Raw Normal View History

2018-06-14 16:22:51 +02:00
#include <iostream>
#include "LargeCowMatrix.h"
int LargeCowMatrix::instanceCounter = 0;
LargeCowMatrix::LargeCowMatrix() : value(-1), referenceCounter(0){
instanceCounter++;
}
LargeCowMatrix::LargeCowMatrix(int value) : value(value), referenceCounter(0){
instanceCounter++;
}
LargeCowMatrix::LargeCowMatrix(const LargeCowMatrix& source) : value(source.value), referenceCounter(source.referenceCounter){
instanceCounter++;
}
LargeCowMatrix::~LargeCowMatrix() {
instanceCounter--;
}
LargeCowMatrix::operator int() {
return value;
}
LargeCowMatrix LargeCowMatrix::operator+(const LargeCowMatrix &other) {
return LargeCowMatrix(value + other.value);
}
LargeCowMatrix &LargeCowMatrix::operator++(int) {
value++;
return *this;
}
bool LargeCowMatrix::operator==(const LargeCowMatrix &other) {
return this->value == other.value;
}
bool LargeCowMatrix::operator!=(const LargeCowMatrix &other) {
return !(*this==other);
}
bool LargeCowMatrix::instanceCountExceeds(int max) {
bool result = instanceCounter>max;
if(result)
std::cout << LargeCowMatrix::instanceCounter << " > max=" << max << std::endl;
return result;
}