Quote:
Originally Posted by iochinome
now for some reason, C++ does not allow me to make a string of characters like that. the error it gives me is
"warning: deprecated conversion from string constant to 'char*'"
|
A warning is just a warning. It still allows you to do that.
Quote:
how do i get around this?
|
The basic problem is that quoted text in C++ has data type
char const*
rather than
char*
To stay most consistent with the original C code, you would use a const cast to get around it.
Code:
dev_name = const_cast<char*>( "/dev/video0" );
I assume the original C code never actually overwrites the quoted text, it simply uses the data type char* when char const* would more accurately describe the data.
It would be better C++ code to change the original declaration to add the const (rather than change the assignment to add a const_cast).
Code:
static char const* dev_name = NULL;
But depending on how dev_name is used elsewhere, that might bring up other errors that need to be fixed. Doing so would end up with more maintainable code than covering the problem with a const_cast but might take more changes to get there. (But maybe it wouldn't take more changes, so you might try changing the declaration first and only if that brings up too many new errors change it back and use the const_cast).