Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. struct subproblem
  2. {
  3. ...
  4. virtual void solve (double& solution, double parameter)=0;
  5. }
  6. struct subproblem0: public subproblem
  7. {
  8. ...
  9. virtual void solve (double& solution, double parameter){...};
  10. }
  11. struct subproblem1: public subproblem
  12. {
  13. ...
  14. virtual void solve (double* solution, double parameter){...};
  15. }
  16.  
  17. int main{
  18. subproblem problem[2];
  19. subproblem[0] = new subproblem0();
  20. subproblem[1] = new subproblem1();
  21. double argument0(0),
  22. argument1(1),
  23. sol0[2],
  24. sol1[2];
  25. for(unsigned int i(0);i<2;++i)
  26. {
  27. problem[i]->solve( &(sol0[i]) , argument0);
  28. problem[i]->solve( &(sol1[i]) , argument1);
  29. }
  30. return 0;
  31. }
  32.  
  33. Arg<T1,T2> argument0(f1,f2)
  34.  
  35. template<T1,T2> solve (double* solution, Arg<T1,T2> parameter)
  36.  
  37. struct param_list_base {
  38. virtual double getParam(int i) const = 0;
  39. };
  40.  
  41. template <typename ParamStorage>
  42. struct param_list : param_list_base {
  43. const ParamStorage& params;
  44. param_list(const ParamStorage& aParams) : params(aParams) { };
  45. virtual double getParam(int i) const {
  46. return params[i];
  47. };
  48. };
  49.  
  50. class subproblem {
  51. protected:
  52. virtual void solve_impl(double* sol, param_list_base* params) = 0;
  53. public:
  54. template <typename ParamStorage>
  55. void solve(double* sol, ParamStorage params) {
  56. param_list<ParamStorage> tmp(params);
  57. solve_impl(sol, &tmp);
  58. };
  59. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement