map/set iterator not dereferencable
От: Sempsey  
Дата: 20.09.10 19:15
Оценка:
Приветсвую!


class Dir {
    typedef map<string,Dir*> dir_t;
    public:
        void print(int spaces);
        Dir* add_subdir(const string& name);
    private:
        dir_t subdirs;
};

Dir* Dir::add_subdir(const string& name){
    dir_t::iterator it;
    bool inserted;
    pair<dir_t::iterator,bool>(it,inserted)=subdirs.insert(pair<string,Dir*>(name,static_cast<Dir*>(NULL)));
    if(inserted==true){
        it->second=new Dir();
    }
    
    return it->second;
}



GCC нормально компилит и выполняет, VS Express компилит, но при за пуске выдает:
Debug Assertion Failed!
Expression map/set iterator not dereferencable.
Подскажите в чем затык и как быть? Спасибо!
visual studio express 10 c++
Re: map/set iterator not dereferencable
От: Vain Россия google.ru
Дата: 20.09.10 19:24
Оценка:
Здравствуйте, Sempsey, Вы писали:

S>Dir* Dir::add_subdir(const string& name){

S> dir_t::iterator it;
S> bool inserted;
S> pair<dir_t::iterator,bool>(it,inserted)=subdirs.insert(pair<string,Dir*>(name,static_cast<Dir*>(NULL)));
S>GCC нормально компилит и выполняет, VS Express компилит, но при за пуске выдает:
S>Debug Assertion Failed!
S>Expression map/set iterator not dereferencable.
S>Подскажите в чем затык и как быть? Спасибо!
Выделено.
[In theory there is no difference between theory and practice. In
practice there is.]
[Даю очевидные ответы на риторические вопросы]
Re: map/set iterator not dereferencable
От: dilmah США  
Дата: 20.09.10 19:27
Оценка:
S> pair<dir_t::iterator,bool>(it,inserted)=subdirs.insert(pair<string,Dir*>(name,static_cast<Dir*>(NULL)));

Ээ.. ты С++ с перлом не перепутал?

std::pair<dir_t::iterator, bool> x = ...
далее используй x.first и x.second
Re[2]: map/set iterator not dereferencable
От: Sempsey  
Дата: 20.09.10 20:00
Оценка:
Здравствуйте, dilmah, Вы писали:

S>> pair<dir_t::iterator,bool>(it,inserted)=subdirs.insert(pair<string,Dir*>(name,static_cast<Dir*>(NULL)));


D>Ээ.. ты С++ с перлом не перепутал?


D>std::pair<dir_t::iterator, bool> x = ...

D>далее используй x.first и x.second

О чорт Спасибо! Так изначально и было. На самом деле для меня непонятно почему необходимо кастовать NULL, gcc сжевал все без кастинга.
Re[3]: map/set iterator not dereferencable
От: Vain Россия google.ru
Дата: 21.09.10 00:55
Оценка:
Здравствуйте, Sempsey, Вы писали:

S>>> pair<dir_t::iterator,bool>(it,inserted)=subdirs.insert(pair<string,Dir*>(name,static_cast<Dir*>(NULL)));

D>>Ээ.. ты С++ с перлом не перепутал?
D>>std::pair<dir_t::iterator, bool> x = ...
D>>далее используй x.first и x.second
S>О чорт Спасибо! Так изначально и было. На самом деле для меня непонятно почему необходимо кастовать NULL, gcc сжевал все без кастинга.
Видимо где-то NULL переопределён так:
#define NULL ((void*)0)

А надо:
#define NULL 0
[In theory there is no difference between theory and practice. In
practice there is.]
[Даю очевидные ответы на риторические вопросы]
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.