I've already gone through the following links but couldn't get it to work:
Adding to c* invalid conversion from const char* to char*"
Why is conversion from string constant to 'char*' valid in C but invalid in C++
I'm working on arduino Uno. I need to send an argument of type char*
to a function. I have the following code:
const char* topic = "SampleTopic";
const char* msg = "Hello";
publish(0, 0, 0, "msgid", topic, msg);
I'm getting this error:
initializing argument 5 of 'void GSM_MQTT::publish(char, char, char, unsigned int, char*, char*)'
void publish(char DUP, char Qos, char RETAIN, unsigned int MessageID, char *Topic, char *Message);
warning: invalid conversion from 'const char*' to 'char*' [-fpermissive]
publish(0, 0, 0, _generateMessageID(), topic, msg);
^
I've even tried using const std::string& topic = "SampleTopic";
but get this error:
'string' in namespace 'std' does not name a type
Even const char* topic = (char*)"SampleTopic";
and passing it as func(topic)
gives the same error.
How can I resolve this ??