xlnt-community / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
https://xlnt-community.github.io/xlnt/
Other
14 stars 3 forks source link

no matching function for call to ‘xlnt::cell::value()’ #40

Closed raphael10-collab closed 4 days ago

raphael10-collab commented 6 days ago

From here: https://xlnt-community.github.io/xlnt/classxlnt_1_1cell.html#a1e034f21e14e3eebe8d4059917537e13

template<typename T >
T xlnt::cell::value (   ) const

Returns the value of this cell as an instance of type T. Overloads exist for most C++ fundamental types like bool, int, etc. as well as for std::string and xlnt datetime types: date, time, datetime, and timedelta.

I understand, but I can be wrong, that I should be able to get the value of the cell in this way:

const double vd = cell.value();

But I get this error: no matching function for call to ‘xlnt::cell::value()’

/usr/local/include/xlnt/cell/cell.hpp:115:7: note:   template argument deduction/substitution failed:
/home/raphy/Grasp/src/main.cpp:3448:53: note:   couldn’t deduce template parameter ‘T’
 3448 |                         const double vd = cell.value();
      |                                           ~~~~~~~~~~^~
/usr/local/include/xlnt/cell/cell.hpp:126:10: note: candidate: ‘void xlnt::cell::value(std::nullptr_t)’
  126 |     void value(std::nullptr_t);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:126:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:131:10: note: candidate: ‘void xlnt::cell::value(bool)’
  131 |     void value(bool boolean_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:131:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:136:10: note: candidate: ‘void xlnt::cell::value(int)’
  136 |     void value(int int_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:136:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:141:10: note: candidate: ‘void xlnt::cell::value(unsigned int)’
  141 |     void value(unsigned int int_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:141:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:146:10: note: candidate: ‘void xlnt::cell::value(long long int)’
  146 |     void value(long long int int_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:146:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:151:10: note: candidate: ‘void xlnt::cell::value(long long unsigned int)’
  151 |     void value(unsigned long long int int_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:151:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:156:10: note: candidate: ‘void xlnt::cell::value(float)’
  156 |     void value(float float_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:156:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:161:10: note: candidate: ‘void xlnt::cell::value(double)’
  161 |     void value(double float_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:161:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:166:10: note: candidate: ‘void xlnt::cell::value(const xlnt::date&)’
  166 |     void value(const date &date_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:166:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:171:10: note: candidate: ‘void xlnt::cell::value(const xlnt::time&)’
  171 |     void value(const time &time_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:171:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:176:10: note: candidate: ‘void xlnt::cell::value(const xlnt::datetime&)’
  176 |     void value(const datetime &datetime_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:176:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:181:10: note: candidate: ‘void xlnt::cell::value(const xlnt::timedelta&)’
  181 |     void value(const timedelta &timedelta_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:181:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:186:10: note: candidate: ‘void xlnt::cell::value(const std::string&)’
  186 |     void value(const std::string &string_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:186:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:191:10: note: candidate: ‘void xlnt::cell::value(const char*)’
  191 |     void value(const char *string_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:191:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:196:10: note: candidate: ‘void xlnt::cell::value(const xlnt::rich_text&)’
  196 |     void value(const rich_text &text_value);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:196:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:201:10: note: candidate: ‘void xlnt::cell::value(xlnt::cell)’
  201 |     void value(const cell other_cell);
      |          ^~~~~
/usr/local/include/xlnt/cell/cell.hpp:201:10: note:   candidate expects 1 argument, 0 provided
/usr/local/include/xlnt/cell/cell.hpp:207:10: note: candidate: ‘void xlnt::cell::value(const std::string&, bool)’
  207 |     void value(const std::string &string_value, bool infer_type);

What am I missing or doing wrong? How to correctly get the value of the cell as a double ?

m7913d commented 5 days ago

The relevant part of the error message is:

/usr/local/include/xlnt/cell/cell.hpp:115:7: note:   template argument deduction/substitution failed:
/home/raphy/Grasp/src/main.cpp:3448:53: note:   couldn’t deduce template parameter ‘T’
 3448 |                         const double vd = cell.value();
      |                                           ~~~~~~~~~~^~

Template argument deduction doesn't work for return types. So you should explicitly specify the template parameter:

const double vd = cell.value<double>();
raphael10-collab commented 4 days ago

Yes. I forgot to specify the type in ..

Thank you