Имах проблем с моя шаблонен клас Queue, който изпълнявах функциите във файл за изпълнение, така че видях този отговор и е решен да направи имплементацията в заглавния файл:
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
И аз извиквам тази функция от моя 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);
...
}
И все още имам тази грешка при компилиране:
# 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
Не знам защо се случва това, ако вече съм посочил функциите за изпълнение в заглавния файл, какво трябва да направя с деструктора?
~Queue()
? - person Yakk - Adam Nevraumont   schedule 22.07.2015~Queue()
не изглежда да е дефиниран. Вие ли го определихте? - person Captain Obvlious   schedule 22.07.2015