Can't assign "const char*" to an entity of type "char*"

I'm fuzzy on pointers I suppose (I figured I could just assign one pointer to the other but I guess not).

1
2
3
4
5
6
7
8

char *myString; //Defined in prototype

TestClass::TestClass(const char *myChar)
{
  myString = myChar;

}


What am I doing wrong?
You have a const char*, meaning you can't modify what is being pointed to, but then you attempt to assign it to a normal char*, which means you *can* modify it. Should be obvious why that's not legal.
use strdup.
*use std::string
I see. Because assigning that pointer would give myString access to that memory location, and since it is not modifyable we get an error. Thanks!
Topic archived. No new replies allowed.