fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. sturct Pidor
  5. {
  6. int v1;
  7. float v2;
  8. }
  9.  
  10. class Serializer
  11. {
  12. public:
  13. template<class T>
  14. void AddField(std::string name, T& field)
  15. {
  16.  
  17. }
  18. }
  19.  
  20. int main() {
  21. // your code goes here
  22. Serializer s;
  23. Pidor p;
  24. s.AddField("v1", p.v1);
  25. s.AddField("v2", p.v2);
  26.  
  27. // а хотелось бы
  28. // for (auto& field : p.static_fields)
  29. //{
  30. // s.AddField(field.name, field.value);
  31. //}
  32.  
  33.  
  34. return 0;
  35. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:1: error: ‘sturct’ does not name a type; did you mean ‘struct’?
 sturct Pidor
 ^~~~~~
 struct
prog.cpp:18:2: error: expected ‘;’ after class definition
 }
  ^
  ;
prog.cpp: In function ‘int main()’:
prog.cpp:23:2: error: ‘Pidor’ was not declared in this scope
  Pidor p;
  ^~~~~
prog.cpp:24:19: error: ‘p’ was not declared in this scope
  s.AddField("v1", p.v1);
                   ^
stdout
Standard output is empty