deprecated conversion from string constant to 'char*'

There are a couple of things going on here.

char *Type = new char[10];

This create a char* pointer named Type and initializes it to point to the first element of a newly allocated 10-element array.

Type = "Access";  // ERROR

This assignment doesn't do what you think it does. It doesn't copy the 6-character string "Access" (7 characters including the terminating '\0') to the array you just created. Instead, it assigns a pointer to the first element of that array into your pointer Type. There are two problems with that.

First, it clobbers the previous value of Type. That 10-character array you just allocated now has nothing pointing to it; you can no longer access it or even deallocate it. This is a memory leak.

This isn't what the compiler is complaining about.

Second, a string literal creates a statically allocated const array ("statically allocated" meaning it exists for the entire execution of your program). Type is not declared with a const qualifier. If the compiler allowed you to point Type to the string "Access", you could use that pointer to (attempt to) modify it:

Type = "Access";
Type[0] = 'a'; // try to change the string to "access"

The purpose of const is to prevent you from modifying, or even attempting to modify, things that are read-only. That's why you're not allowed to assign a non-const pointer value to a const pointer object.

Since you're programming in C++, you're probably better off using std::string.


If you really want to modify Type:

char *Type = new char[10];
strcpy( Type, "Access" );

If you don't want to modify access:

const char *Type = "Access";

Please note, that, however, arrays of char in C and in C++ come with a lot of problems. For example, you don't really know if the call to new has been successful, or whether it is going to throw an exception. Also, strcpy() could surpass the limit of 10 chars.

So you can consider, if you want to modify type later:

std::string Type = "Access";

And if you don't want to modify it:

const std::string Type = "Access";

... the benefit of using std::string is that it is able to cope with all these issues.