JalaliMehr
شنبه 30 مرداد 1389, 15:27 عصر
سلام.
يك كلاسي تعريف شده كه از Template استفاده مي كنه به صورت زير و هيچ مشكلي نداره.
// Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using std::cout;
template <class T>
class Test
{
public:
void ShowMsg(T Value);
};
template <class T>
void Test<T>::ShowMsg(T Value)
{
cout<< Value;
}
int _tmain(int argc, _TCHAR* argv[])
{
Test<int> a;
a.ShowMsg(12);
return 0;
}
همين كلاسي كه از template استفاده كرده رو در يك فايل headerو C++ مجزا پياده كردم مشكل مي گيره اشكال از چي مي تونه باشه
// Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "TetsCls.h"
int _tmain(int argc, _TCHAR* argv[])
{
CTetsCls<int> a;
a.ShowMsg(12);
return 0;
}
//TestCls.cpp
#include "StdAfx.h"
#include "TetsCls.h"
#include <iostream>
using std::cout;
template <class T>
CTetsCls<T>::CTetsCls(void)
{
}
template <class T>
CTetsCls<T>::~CTetsCls(void)
{
}
template <class T>
void CTetsCls<T>::ShowMsg(T Value)
{
cout << Value;
}
//TestCls.h
#pragma once
template <class T>
class CTetsCls
{
public:
CTetsCls(void);
~CTetsCls(void);
void ShowMsg(T Value);
};
يك كلاسي تعريف شده كه از Template استفاده مي كنه به صورت زير و هيچ مشكلي نداره.
// Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using std::cout;
template <class T>
class Test
{
public:
void ShowMsg(T Value);
};
template <class T>
void Test<T>::ShowMsg(T Value)
{
cout<< Value;
}
int _tmain(int argc, _TCHAR* argv[])
{
Test<int> a;
a.ShowMsg(12);
return 0;
}
همين كلاسي كه از template استفاده كرده رو در يك فايل headerو C++ مجزا پياده كردم مشكل مي گيره اشكال از چي مي تونه باشه
// Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "TetsCls.h"
int _tmain(int argc, _TCHAR* argv[])
{
CTetsCls<int> a;
a.ShowMsg(12);
return 0;
}
//TestCls.cpp
#include "StdAfx.h"
#include "TetsCls.h"
#include <iostream>
using std::cout;
template <class T>
CTetsCls<T>::CTetsCls(void)
{
}
template <class T>
CTetsCls<T>::~CTetsCls(void)
{
}
template <class T>
void CTetsCls<T>::ShowMsg(T Value)
{
cout << Value;
}
//TestCls.h
#pragma once
template <class T>
class CTetsCls
{
public:
CTetsCls(void);
~CTetsCls(void);
void ShowMsg(T Value);
};