LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-19-2009, 05:52 AM   #16
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197

Quote:
Originally Posted by iochinome View Post
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).

Last edited by johnsfine; 05-19-2009 at 05:55 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
xemacs syntax highlighting only works on string literals! (Slackware) turbo_spool Linux - Software 3 11-22-2007 10:25 AM
how to use vim has color syntax on ubuntu pk_kala Ubuntu 4 09-08-2007 04:17 PM
syntax error in string trim and wrong node routing agent in tcl script newbie06 Linux - General 0 02-23-2007 02:00 AM
need snmp syntax to change a community string RedhatES4_user Linux - Software 1 02-12-2007 06:47 AM
How to cin >> string? kornerr Programming 2 11-01-2005 03:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration