2

I have overloaded function

int put_message(int level, int sys_log_level, const char * inp_message);
int put_message(int level, int sys_log_level, const std::string &inp_message);

and call this function

put_message(0, LOG_ERR, "clock_gettime error");

Code is compiled and works but Eclipse CDT Code analyzer says

Invalid arguments ' Candidates are: int put_message(int, int, const char *) int put_message(int, int, const ? &) '

How can I fix this the error?

Update: After modifying LOG_ERR to int(LOG_ERR) error disappears. I have not add the in the header. Adding solves the problem.

Egor
  • 31
  • 5

2 Answers2

0

you are missing #include <string> or something related to string class

greywolf82
  • 21,813
  • 18
  • 54
  • 108
-2

You need to cast the string to the correct type, the compiler treats "some string" as char[] so you need to cast it to const char*

Try with

put_message(0, LOG_ERR, (const char*)"clock_gettime error");
Henry
  • 54
  • 7
  • Nope. `const char[]`s decay into `const char*`, whereas `std::string` requires a user-defined conversion. – L. F. Jun 06 '19 at 07:17
  • It should do if you pass the variable that corresponds to a pointer to the first char in the array but I've seen cases like this where a cast was required for string literals. Whether thats a bug in the code analyser as you said, I don't know – Henry Jun 06 '19 at 07:24
  • @Henry, I have try this. No changes. But I try (type)(val) for other arguments and find out source of error. – Egor Jun 07 '19 at 08:36