class NonZeroSample{
protected:
virtual intnxt = 0;
public:
int nxtNonZero() {
int value;
do {
value = this->intnxt();
}while(value ==0);
return value;
}
};
Nigh um-possible to say what is wrong with that snippet, it is without any context of application. It would need a crap load of framework code to be written to figure out what, if anything, is wrong.
1. A Short, Self Contained, Correct (Compilable), Example sure would help. http://www.sscce.org/
c++ does not have virtual variables, does it? I am not up on the new 20 deep details, but last I heard, that was not a thing. It also lacks a type, assuming you wanted an int on it?
you can fake a virtual variable by providing getter/setter that are virtual and overriding what they do up the inheritance chain.
it looks like you are trying to do some sort of linked list weirdness. Details are required...
#include <iostream>
class NonZeroSample {
protected:
staticconstint intnxt = 0;
public:
int nxtNonZero() {
int value;
// infinite loop
do {
value = this->intnxt;
std::cout << "loop" << std::endl;
} while (value == 0);
// never reached
return value;
}
};
int main()
{
NonZeroSample *sample = new NonZeroSample();
std::cout << "output " << sample->nxtNonZero() << std::endl;
delete sample;
}
Change the value of the integer intnxt (line 6) in order to see the output. In your code, while the integer is equal to zero, it runs without breaking. So you create an infinite loop :/