c++ - Binding one class to another -



c++ - Binding one class to another -

suppose have class defines specific problem, example, value of function. function can take specific parameters, i.e. biased constraints. here simple example:

class problem { private: std::function<double(const std::vector<double>&)> d_func; std::vector<std::pair<double,double>> d_constraints; public: double evaluate(const std::vector<double>& args) { homecoming d_func(args); } bool iswithindomain(const std::vector<double>& args) { /*check whether args in domain defined d_constraints*/ } };

and there class solution holds parameter can passed function defined in problem , value of function:

class solution { private: std::vector<double> d_solution; double d_value; };

i can have lot of possible solution's have same boundaries , function passed into. question is: best way incorporate problem's info solution? 1 solution have pointer problem within solution, if constraints or function changed in problem have updated version of in every solution instances. since c++11 deprecated utilize raw pointers, have go shared_ptr, have performance issues...

any help highly appreciated!

raw pointers not (and never be) deprecated. owning raw pointers deprecated (or discouraged). if have else owning problem instances, having raw pointer them within solution fine. you'll have create sure no solution outlives problem, of course.

if solutions own problem objects, however, should turn shared ownership. mentioned std::shared_ptr has performance issues - mean? yes, copying or destroying shared_ptr requires atomic operations, dereferencing not. have done profiling sure actual problem?

never of import design decisions based on feeling inefficient. measure first.

c++ pointers c++11 constraints

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -