Compiler warnings.


R. Clayton (rclayton@monmouth.edu)
(no date)


  I've writting the following code

    ostringstream message;
    message << *this;
    document.size=message.str().size();
    document.data = new char [document.size];
    document.data = message.str().c_str();

  and gcc is complaining about

    LList.cc:55: warning: invalid conversion from `const char*' to `char*'

  While this is just a warning and the code seems to work, is there a better
  way to do this?

In this case you should pay attention to the warning, because it's pointing to
a particularly odious bit of coding, one that will cause your code to fail
tests.

You want to ask yourself the question "What's being returned by
std::string::c_str()?" Nyhoff Section 3.4 sort of answers this question, but
Deitel and Deitel tells you what you need to know (look up c_str in the index;
I'm using the third, purple edition, but I imagine the other editions are the
same in this respect).

Once you've figured out the const char * problem, you should be in a position
to figure out what's wrong with

  document.data = new char [document.size];
  document.data = message.str().c_str();

I'll give you a hint: there's two things wrong with this code, both of them
unforgivably bad (and it has nothing to do with document.size being zero).



This archive was generated by hypermail 2.0b3 on Mon Dec 15 2003 - 19:45:06 EST