Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 26th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Class Return Type Overloading
  2. class data {
  3. public:
  4.     double error;
  5.     double value;
  6.  
  7.     ...
  8. }
  9.  
  10. ...
  11.  
  12. data *outputs;
  13.  
  14. ...
  15.  
  16. double lastValue = ...;
  17. double someValue = ...;
  18.  
  19. for (int i = 0; i < n; ++i) {
  20.     outputs[i] = someValue; //should be equivalent to outputs[i].value = someValue
  21.     outputs[i].error = lastValue - someValue;
  22. }
  23.        
  24. class data {
  25. public:
  26.     double error, value;
  27.  
  28.     void operator=(double d) { value = d; }
  29. };
  30.        
  31. class data {
  32. public:
  33.     double error, value;
  34.     data(double value_arg, double error_arg)
  35.         : value(value_arg), error(error_arg) { }
  36. };
  37.        
  38. outputs[i] = data(someValue, lastValue - someValue);