i am using Qt5 creator , all the files are included in the project (the class "MyCounter" is created using the IDE wizard) i reduced my code to this one, and when i compile and run:
undefined reference to MyCounter<int>::MyCounter()
main.cpp
#include <QCoreApplication>
#include"mycounter.h" //if include "mycounter.cpp" instead of "mycounter.h" works fine
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyCounter<int> x;
return a.exec();
}
mycounter.h
#ifndef MYCOUNTER_H
#define MYCOUNTER_H
template<class T>
class MyCounter
{
public:
MyCounter();
};
#endif // MYCOUNTER_H
mycounter.cpp
#include "mycounter.h"
#include <iostream>
template<class T>
MyCounter<T>:: MyCounter()
{
std::cout<<"somthing...";
}