Why do I get cannot convert from const char[5] to char* in VS?

1.7k views Asked by At
char* f() {
   cout << b;
   return "B::f";
}

Ok so I have this piece of code inside a class and I keep get this error

'return': cannot convert from 'const char [5]' to 'char*'

I tried some online compilers and it works just fine .

So why is this happening ?

1

There are 1 answers

0
Kit Fisto On BEST ANSWER

The return type of this function indicates that the storage it points to can be changed. However you return a literal, which does not allow modifications.

Change the signature to

const char* f();

and it will work.