C++ / boost : declaring an encapsulated shared_array -


i started use smart pointers. if correct, smart pointers declared:

shared_array<double> a(new double[n]); 

but how if encapsulated in class ? moment doing follow, seems super ugly:

header file:

class foo { public:     foo(int size);     shared_array<double> _a; }; 

source file

foo::foo(int n){     shared_array<double> p (new double[n]);     _a = p; } 

you can use constructor initialization list:

foo::foo(int n) : _a(new double[n]) {} 

in case need set managed array in constructor's body, then

foo::foo() {   int n = somecalculation();   _a.reset(new double[n]); } 

Comments

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -