C++ syntax

when I use a function - ( char *str)

and pass some string to it println(“This is a test”);, for example, I get a warning message " deprecated conversion from string constant to 'char*"

compiled in gcc in qt4.

whats the new syntax or the right syntax…

which book would is better
**C++ How to Program (7th Edition)/6th edition, seventh edition has 1100 pages and 6th edition has 1500 pages, which one to go for, both by Dietel and Dietel.
**

It’s not a syntax issue, but a semantics issue. String constants are of type const char * and are strictly not supposed to be passed to functions that expect a char * argument because in principle the function could modify its argument. Which would actually fail because the program would be attempting to write into a read-only area of memory.

The best solution is to rewrite the function to expect const char *. However this may lead to a cascade of modifications required in functions that are called from your function.

Less elegant is to copy the const char * to an writable string array. This is not elegant because it’s an extra copy to avoid a warning message.

Or you could ignore the warning and hope that your function never tries to modify the const char * buffer either directly or indirectly.

It’s a warning and not fatal because lots of pre-ANSI C programs didn’t have this tight type checking and making it a compile error would break a lot of those compilations.

thanks a lot for clearing the air, and which book would be better of the two, and any documentation available anywhere of better of new style for semantics of C++, and have read else where that this year new draft of ISO C++ would be released.

Sorry, I don’t know much about C++ books, it’s been so long since I learnt C/C++. I’m sure a search will find you some reviews.

shri75 wrote:

>
> thanks a lot for clearing the air, and which book would be better of
> the two, and any documentation available anywhere of better of new
> style for semantics of C++, and have read else where that this year
> new draft of ISO C++ would be released.

There is a new C++ standard due to be released C++0x :

http://en.wikipedia.org/wiki/C%2B%2B0x


Per Jessen, Zürich (17.4°C)
http://en.opensuse.org/User:pjessen

thanks to both of you, no problems regarding the book, only searching for some good book which has lot of examples and some real time projects, to get an idea of what one needs to know, and how to implement in real scenario…:slight_smile:

shri75 wrote:

>
> thanks to both of you, no problems regarding the book, only searching
> for some good book which has lot of examples and some real time
> projects, to get an idea of what one needs to know, and how to
> implement in real scenario…:slight_smile:

Grady Booch has written a few books on object oriented design, I’ve got
at least two somewhere.


Per Jessen, Zürich (17.7°C)
http://en.opensuse.org/User:pjessen

^

could you please let me know the name of books and publisher.

ok just checked amazon, they are very old publications, I want some thing new publication, also covering C++0X standard or at-least introducing the concept, like in this book - **C++ How to Program (7th Edition) by dietel and dietel **, not yet checked the book, however in synopsis , it was mentioned as introducing C++0x.

char test ] = “Thisisatest”; println (test);