'Infinite loop in a C++ constructor [closed]
I've got this class in c++ and I'm having trouble with the second constructor: for some unknown reason, the IDE is acusing an infinite loop. I don't have any idea what is causing it, since I've written similar loops countless times. The code in question is this:
class ArithmeticProgression : protected Progression{
//Constructors
explicit ArithmeticProgression(double reason) : Progression(){
this->reason = reason;
}
ArithmeticProgression(double reason, int maxIndex) : Progression(){
this->reason = reason;
for(int i = 0; i < maxIndex; i++){
}
}
//Destructor
~ArithmeticProgression(){
delete this;
}
protected:
double reason;
};
Solution 1:[1]
You must be reading it wrong, because the infinite loop is in your destructor:
~ArithmeticProgression(){
delete this;
}
You keep invoking it from within itself for absolutely no sane reason.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Blindy |
