c++ - How do you correctly initialize a struct with a member that is a const pointer to a const value? -


currently i'm doing this:

struct foo {     const int         *const a,         *const b,          *const c;      foo(int a, int b, int c)             : a(_a), b(_b), c(_c)     {         *_a = a;         *_b = b;         *_c = c;     }  private:     int _a[1], _b[1], _c[1];  }; 

but there way without putting in second set of pointers (_a, _b, _c)?

but there way without putting in second set of pointers (_a, _b, _c)?

sure. can use:

foo(int a, int b, int c)         : a(new int(a)), b(new int(b)), c(new int(c)) {} 

keep in mind the rule of three , implement copy constructor, copy assignment operator , destructor appropriately foo.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -