Mam szablon klasy:
#include <string>
template <typename T1>
class App
{
public:
T1 a;
App();
~App();
};
Jak chcę utworzyć obiekt tej klasy w ten sposób:
App <std::string> abc123;
To kompilator wyrzuca błąd:
undefined reference to `App<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>::App()'
Dlaczego tak się dzieje? Nie można przekazywać typu string jako parametru temlate?
Oto 3 pliki dla których pojawia się błąd:
main.cpp
#include <string>
#include "App.h"
int main()
{
App <std::string> app;
return 0;
}
App.h
#ifndef APP_H
#define APP_H
#include <iostream>
#include <string>
template <class T1>
class App
{
public:
T1 a;
App();
~App();
};
#endif // APP_H
App.cpp
#include "App.h"
template <typename T1>
App<T1>::App()
{
}
template <typename T1>
App<T1>::~App()
{
}