I want create class with pattern of function. When I add definition of function to *.cpp file and call it in mainwindow.cpp, I have bugs:
mainwindow.o:-1: error: In function `ZN10MainWindowC2EP7QWidget':
mainwindow.cpp:6: undefined reference to `readmemory::readmemory()'
mainwindow.o:-1: error: In function `ZN10MainWindowC1EP7QWidget':
mainwindow.cpp:6: undefined reference to `readmemory::readmemory()'
mainwindow.o:-1: error: In function `ZN10MainWindow11startSearchEv':
mainwindow.cpp:46: undefined reference to `void readmemory::test<int>(int)'
:-1: error: collect2: ld returned 1 exit status
mainwindow.o:-1: error: In function `ZN10MainWindowC2EP7QWidget':
mainwindow.cpp:6: undefined reference to `readmemory::readmemory()'
mainwindow.o:-1: error: In function `ZN10MainWindowC1EP7QWidget':
mainwindow.cpp:6: undefined reference to `readmemory::readmemory()'
mainwindow.o:-1: error: In function `ZN10MainWindow11startSearchEv':
mainwindow.cpp:46: undefined reference to `void readmemory::test<int>(int)'
:-1: error: collect2: ld returned 1 exit status
To copy to clipboard, switch view to plain text mode
It's my exemplary code:
class.h
class Pattern{
template<typename T> void function(T);
};
class Pattern{
template<typename T> void function(T);
};
To copy to clipboard, switch view to plain text mode
class.cpp
template<typename T>
void Pattern::function(T a)
{
//code
}
template<typename T>
void Pattern::function(T a)
{
//code
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
Pattern patternClass;
int a;
patternClass.function(a);
Pattern patternClass;
int a;
patternClass.function(a);
To copy to clipboard, switch view to plain text mode
I tried use "export" like in Visual Studio and include class.cpp to class.h, but it doesn't work. Is it possible to use template like in my test code?
Bookmarks