List declaration - Access violation

Hello.
I tried to declare list in header file:

private list<MyClass*> _objects;

In .cpp file I implemented method for appending object:

1
2
3
4
void Document::append(MyCLass *o)
{
    _objects.push_back(o);
}


It chrashes when I try to push_back an object.
The message I got is "Access violation".

If I put some other function, for example _objects.size(), it chrashes, too.
So I realized that list is not accessible.

If I declare list in that method (not in header file), then it is ok:
1
2
3
4
5
void Document::append(MyCLass *object)
{
    list<MyCLass*> _objects;
    _objects.push_back(object);
}


It's interesting that if I use VECTOR, I don't have such problems..
But I need to work with LIST, not VECTOR.

If anybody can help me...

Thank You !
Is _objects declared as a member of the class Document?

Also are we talking about std::list?
Last edited on
Yes, in header file i have:

1
2
3
4
5
6
7
8
9
class Document
{
private:
    list<MyClass*> _objects;
    ...
public:
    void append(MyClass* o);
    ...
}


Yes, we're talking about std::list
Last edited on
I cannot reproduce this error, unless there are things going on that I'm not aware of, it looks fine. Have you tried rebuilding, or even closing down your ide and restarting your solution?
Yes, I tried everything. It takes me a couple of days.

I also try with type int:
1
2
3
4
5
6
7
8
9
class Document
{
private:
    list<int> _objects;
    ...
public:
    void append(int o);
    ...
}


1
2
3
4
void Document::append(int o)
{
    _objects.push_back(o);
}


The only way that works is using vector:
1
2
3
4
5
6
7
8
9
class Document
{
private:
    vector<MyClass*> _objects;
    ...
public:
    void append(MyClass* o);
    ...
}


1
2
3
4
void Document::append(MyClass* o)
{
    _objects.push_back(o);
}


It's the same code, but vector works, list doesn't..

By the way, thanks for replying..
Last edited on
Ok, I SOLVED IT..

It was my mistake.. But interesting that worked with vector :-S
Did you end up using vector or solved it for list?
Yes, I solved it for list.

It wasn't problem with list.
Problem was in accessing Document object. It didn't seem like that first, so I make a wrong conclusion..

anyway, Thank You..
Topic archived. No new replies allowed.