I had a problem with my template class Queue which I had been implementing the functions in a implementation file, so I saw this answer and resolved to do the implementation in the header file:
Queue.hpp
#ifndef QUEUE_HPP
#define QUEUE_HPP
#include "Instruction.hpp"
#include "MicroblazeInstruction.hpp"
#include <memory>
#include <list>
template<typename T>
class Queue{
public:
Queue(unsigned int max): maxSize{max} {};
~Queue();
std::list<T> getQueue(){
return queue;
};
void push(T obj){
if(queue.size() < maxSize){
queue.push_front(obj);
}
else{
queue.pop_back();
queue.push_front(obj);
}
};
private:
Queue(const Queue&);
Queue& operator=(const Queue&);
unsigned int maxSize;
std::list<T> queue;
};
#endif
And I call this function from my main:
#include "icm/icmCpuManager.hpp"
#include "Instruction.hpp"
#include "MicroblazeInstruction.hpp"
#include "CpuManager.hpp"
#include "File.hpp"
#include "Utils.hpp"
#include "MbInstructionDecode.hpp"
#include "Queue.hpp"
#include "PatternDetector.hpp"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <sstream>
#include <cstdint>
#include <memory>
int main(int argc, char *argv[]){
...
// Create pointer to microblaze instruction
std::shared_ptr<MicroblazeInstruction> newMbInstruction;
// Maximum pattern size
const unsigned int maxPatternSize = 300;
// Creating the Queue
Queue<std::shared_ptr<MicroblazeInstruction>> matchingQueue(maxPatternSize);
...
}
And I still have this compilation error:
# Linking Platform faith.exe
g++ ./CpuManager.o ./Instruction.o ./File.o ./Utils.o ./MicroblazeInstruction.o ./MbInstructionDecode.o ./PatternDetector.o ./main.o -m32 -LC:\Imperas/bin/Windows32 -lRuntimeLoader -o faith.exe
./main.o:main.cpp:(.text.startup+0x552): undefined reference to `Queue<std::shared_ptr<MicroblazeInstruction> >::~Queue()'
./main.o:main.cpp:(.text.startup+0x83a): undefined reference to `Queue<std::shared_ptr<MicroblazeInstruction> >::~Queue()'
c:/mingw/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.7.0/../../../../i686-w64-mingw32/bin/ld.exe: ./main.o: bad reloc address 0x0 in section `.ctors'
collect2.exe: error: ld returned 1 exit status
makefile:24: recipe for target 'faith.exe' failed
make: *** [faith.exe] Error 1
I don't know why is this happening if I already specified the implementation functions in the header file, what do I have to do with the destructor?