|
![](/i/fill.gif) |
Orchid XP v8 nous illumina en ce 2008-10-04 14:37 -->
> Hmm, and I though everything was going so well. :-/
>
> OK, any C++ experts have any idea why this code snippet causes my
> program to crash at runtime?
>
> typedef std::vector<bool> Codeword;
>
> std::string codeword(const Codeword &c)
> {
> std::string out;
>
> for (unsigned int i=0; i<c.size(); i++)
> if (c[i]) out.append("1"); else out.append("0");
>
> return out;
> }
>
> "Unhandled exception at 0x00414166 in Huffman01.exe: 0xC0000005: Access
> violation reading location 0x00000004."
>
> The code looks fine to me - but what I do know?
>
Maybe you have an uninitialised pointer.
Do you get any output? If you don't, it mean that the variable "c" don't get
initialised properly.
Look at the caller. Maybe the variable that is supposed to be passed is in fact
a null, or an uninitialised pointer, or maybe a constant.
--
Alain
-------------------------------------------------
"The way England treats her prisoners, she doesn't deserve to have any."
--Oscar Wilde
Post a reply to this message
|
![](/i/fill.gif) |