Возникла проблема с использованием шаблонов класса.
// testtemplate.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include "cab.h"
int _tmain(int argc, _TCHAR* argv[])
{
Cab<char> q;
std::cout << q.get(100);
return 0;
}
// Cab.h
#pragma once
template <class T>
class Cab
{
public:
Cab(void);
int get(T data);
private:
int val;
};
// Cab.c
#include "Cab.h"
template <class T> Cab<T>::Cab()
{
val = 10;
}
template <class T> int Cab<T>::get(T data)
{
return data * val;
}
В процессе линковки выдает ошибки
error LNK2001: unresolved external symbol "public: int __thiscall Cab<char>::get(char)" (?get@?$Cab@D@@QAEHD@Z) testtemplate.obj testtemplate
error LNK2001: unresolved external symbol "public: __thiscall Cab<char>::Cab<char>(void)" (??0?$Cab@D@@QAE@XZ) testtemplate.obj testtemplate
Среда VS 2008
Если объявление класса и реализацию поместить в файл testtemplate.cpp (main) ошибки нет.