|
-
June 30th, 2009, 06:16 PM
#1
unresolved externals with templates
I already checked the FAQ and the first 2 solutions did not work.
The third solution worked, but i want to keep my .h and .cpp files seperate, and know why this actualy occurs.
Here is the code:
// header.h
#pragma once
//////////////////////////////
template <class T>
class base
{
protected:
T data;
public:
T getData();
};
// header.cpp
#include "header.h"
//////////////////////////////
template <class T>
T base<T>::getData()
{
return data;
}
// main.cpp
#include "header.h"
#include <iostream>
using namespace std;
void main()
{
base<int> x;
cout << x.getData();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|