c++ - Uninitialized constant members in classes -


this ridiculously easy question, i've been searching around answer while yet can't seem figure out. i'm trying initialize constant variable constant pointer in class. here header file:

class scheduler{   public:   scheduler();   explicit scheduler( unsigned long * );    private:   const unsigned long *const thresh;  }; 

and here constructor class

scheduler::scheduler( unsigned long * threshold ):   thresh(threshold) {} 

when attempt compile code run error:

scheduler.cpp: in constructor ‘scheduler::scheduler()’: scheduler.cpp:3: error: uninitialized member ‘scheduler::thresh’ ‘const’ type ‘const long unsigned int* const’ 

multiple sources online discussing constant member variables in constructors member variables point using initializer lists. think i'm doing i'm supposed to, apparently it's still no good. can see what's wrong?

you must initialize constant member in initialization list of all constructors. doing 1 argument. default 1 too, , fne. in particular case, either initialize thresh 0, or disable default constructor.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -