Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 24th, 2010  |  syntax: C++  |  size: 0.61 KB  |  views: 87  |  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. template <class T, class Pred>
  2. T ConditionalInput(LPSTR inputMessage, LPSTR errorMessage, Pred condition)
  3. {
  4.         T input
  5.         cout<< inputMessage;
  6.         cin>> input;
  7.         while(!condition(input))
  8.         {
  9.                 cout<< errorMessage;
  10.                 cin>> input;
  11.         }
  12.         return input;
  13. }
  14.  
  15. ...
  16.  
  17. int row;
  18.  
  19. row = ConditionalInput("Input the row of the number to lookup, row > 0: ", "[INPUT ERROR]: Specified number is not contained in the range [row > 0]. Please type again: ", [](int x){ return x > 0; });
  20.  
  21. ...
  22.  
  23. The error is:
  24.  
  25. Error   1       error C2783: 'T ConditionalInput(LPSTR,LPSTR,predicate)' : could not deduce template argument for 'T' c_main.cpp        17      1
clone this paste RAW Paste Data