I am new to C++ and I am trying to do the following:
class abc {
public:
int no_of_consumer;
struct def {
int p = 0;
int c = 0;
};
def variable[no_of_consumer - 1];
};
int main() {
abc obj1;
obj1.no_of_consumer = 1;
};
I want the variable no_of_consumer
to be set by the main()
function, so that I can use this variable to define a structure array for variable def
. But I am getting this error:
invalid use of non-static data member "no_of_consumer".
Am I missing some concept here?
no_of_consumer
must be a compile time constant. Use std::vector for dynamically sized arrays.no_of_consumer - 1
why -1?