fork download
  1. /* Row */
  2. struct T_cash_account_row {
  3.  
  4. // Fields:
  5. enum T_field_enum { amount_of_money_e, gender_e, age_e, code_e, height_e, /*<<<<<- add fields here (with index) */
  6. last_e /*<<<<<- add included fields here (without index) */
  7. };
  8. static_assert(last_e > 0, "Number of indexed fields in enum of T_user_row must be greater than 0!");
  9.  
  10. unsigned code:20; // 0 - 1000000
  11. unsigned gender:1; // 0 - 1
  12. unsigned age:7; // 0 - 100
  13. unsigned amount_of_money:20; // 0 - 1000000
  14. int height; // 0 – 300
  15.  
  16. // Get field value
  17. template<int field_enum> inline unsigned get_field_value();
  18. template<int field_enum> inline int get_field_value();
  19.  
  20. static_assert(5 == last_e, "Add/delete new field-case and correct this assert!");
  21. };
  22.  
  23. template<> inline unsigned T_cash_account_row::get_field_value<T_cash_account_row::code_e>() { return code; }
  24. template<> inline unsigned T_cash_account_row::get_field_value<T_cash_account_row::gender_e>() { return gender; }
  25. template<> inline unsigned T_cash_account_row::get_field_value<T_cash_account_row::age_e>() { return age; }
  26. template<> inline unsigned T_cash_account_row::get_field_value<T_cash_account_row::amount_of_money_e>() { return amount_of_money; }
  27. template<> inline int
  28. T_cash_account_row::get_field_value<T_cash_account_row::height_e>() { return height; }
  29. template<> inline unsigned T_cash_account_row::get_field_value<T_cash_account_row::last_e>() { return 1; }
  30. /* ----------------------------------------------------------------------- */
  31.  
  32. int main() {
  33. T_cash_account_row *row = new T_cash_account_row;
  34. auto code = row->get_field_value<T_cash_account_row::code_e>();
  35.  
  36. return 0;
  37. }
  38.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:34:66: error: call of overloaded ‘get_field_value()’ is ambiguous
prog.cpp:34:66: note: candidates are:
prog.cpp:23:29: note: unsigned int T_cash_account_row::get_field_value() [with int field_enum = 3]
prog.cpp:18:38: note: int T_cash_account_row::get_field_value() [with int field_enum = 3]
prog.cpp:34:66: error: unable to deduce ‘auto’ from ‘<expression error>’
prog.cpp:34:10: warning: unused variable ‘code’ [-Wunused-variable]
stdout
Standard output is empty