fork download
  1. void validate(char const* first, char const* last) {
  2. for(; first != last; ++first) {
  3. if(*first == 'X') throw "How dare you put an 'X' here?";
  4. }
  5. }
  6.  
  7. // Base
  8. struct text {
  9. text(char const* first, char const* last)
  10. : storage(first, last) {} // need to pass first and last to validate() first
  11.  
  12. std::string storage;
  13. }
  14.  
  15. // Option #1
  16. struct validated {
  17. validated(char const* first, char const* last) {
  18. validate(first, last);
  19. }
  20. };
  21.  
  22. struct text : validated {
  23. text(char const* first, char const* last)
  24. : validated(first, last) // a bit ugly, if you ask me
  25. storage(first, last) {}
  26.  
  27. std::string storage;
  28. }
  29.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:12: error: ‘string’ in namespace ‘std’ does not name a type
prog.cpp: In constructor ‘text::text(const char*, const char*)’:
prog.cpp:10: error: class ‘text’ does not have any field named ‘storage’
prog.cpp: At global scope:
prog.cpp:20: error: multiple types in one declaration
prog.cpp:22: error: redefinition of ‘struct text’
prog.cpp:8: error: previous definition of ‘struct text’
prog.cpp:28: error: expected unqualified-id at end of input
stdout
Standard output is empty