Well I managed to get it to work with the following alterations:
template.h
Code:
#include <cstdio>
#include <queue>
#include <deque>
class Test {
public:
Test();
void pushANumber(int num);
private:
std::queue<int,std::deque<int> > *intQueue;
std::queue<int,std::deque<int> > secondQueue; //No longer use a pointer
};
template.cpp
Code:
Test::Test (){
// No longer need to do this
std::queue<int,std::deque<int> > *intQueue = new std::queue<int,std::deque<int> >;
}
void Test::pushANumber(int num){
//intQueue->push(num);
secondQueue.push(5);
}
int main (int argc, char** argv){
Test *t = new Test();
printf("This is some rubbish.\n");
//t->pushANumber(5);
t->pushANumber(6);
printf("This is some rubbish.\n");
return 0;
}
This is my misunderstanding of how the memory is allocated. I needed a queue created for every instance of my class I instantiate with 'new'. I assumed that a template is seen as an object which can be allocated HEAP memory or dynamic memory. It must be that a pointer to the Template is allocated on the stack, which points to the heap. I can live with that just as long as I get a new queue for each instantiation.. which looks as though I do when I inspect using a debugger.