Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize static const pointer in a class?

class School
{
    static const int *classcapacity; 
};

This expression is from my exam and it need to get initialized how can i do that ?


2 Answers

You can initialize it in your source file, outside of the body of the class, just as you would any other static member variable, i.e.:

const int* School::classCapacity(new int(42));
like image 186
James McNellis Avatar answered Sep 17 '26 02:09

James McNellis


Probably this way:

class School{
  static const int *classcapacity   ;
};
const int *School::classcapacity = 0;
like image 25
AareP Avatar answered Sep 17 '26 00:09

AareP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!