Deque question

Just started playing around with containers and am trying to create a Deque that will hold pointers to objects. (I'm not sure if its a good idea to do that but i would love your input).

But i get errors when i try to push_back a pointer. Heres my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <deque>
using namespace std;

class Object{
    public:
        Object(){cout << "constructed \n";};
        ~Object(){cout << "destructed \n";};
        int ID;
        int value;
};

int main(){
deque <Object> myObjectDeck;
Object * myObject = new Object;

myObjectDeck.push_back(myObject);       // <----error is here
myObject->ID = myObjectDeck.size();

delete myObject;
myObjectDeck.pop_back();

return 0;
}
@Line 14:
Shouldn't that be deque <Object*>? You're trying to use push_back() which is expecting an Object (because of the type of the deque), but you're giving it an Object*.

-Albatross
Last edited on
ah yes your right. I knew I had to specify it would contain POINTERS but I did not know how to do that. All is right in the world. Thanks a bunch!

P.S.
That simple suggestion just solved a bunch of my headaches with pointers lol
Last edited on
Topic archived. No new replies allowed.