help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bizarre backtrace when trying to initialize std::map with std::pair


From: Benjamin Collins
Subject: Re: bizarre backtrace when trying to initialize std::map with std::pair array
Date: Wed, 27 Jun 2007 19:39:01 -0000
User-agent: G2/1.0

On Jun 27, 2:09 pm, red floyd <no.s...@here.dude> wrote:
>
> You error is on 23.  sizeof(pairs) is much larger than the number of
> entries, so you're running off the end of pairs[].  You either need to
> use sizeof(pairs)/sizeof(mypair_t), or since it's a run-time value:
>

Yes, thank you.  I had seen the array_size template function before,
but it didn't occur to me that having an invalid pointer would cause
the problem I saw.  I used it and it all worked, I think.  I was about
to write another paragraph about how I still didn't get it, but I
neglected to look down in the sources of insert_unique (std_tree.h:
996) where it's clear that the pointer changed because it was supposed
to, and I just misinterpreted the gdb stacktrace.  Now I'm clear about
why the incorrect second iterator blew me up.

> int main()
> {
>      std::map<std::string, void(*)()> mymap(pairs, array_size(pairs));
>
> }

I think you meant

std::map<std::string, void(*)()> mymap(paris, pairs
+array_size(pairs)));

right?  The second (non-default, non-copy) map constructor takes two
iterators, not an interator and a size.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]