首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

模版使用有关问题,想得到T指针类型//怎么处理?T*不行吗

2013-11-13 
模版使用问题,想得到T指针类型//怎么办???T*不行吗?#include stdafx.h#include iostreamusing namespa

模版使用问题,想得到T指针类型//怎么办???T*不行吗?


#include "stdafx.h"
#include <iostream>
using namespace std;

template <typename T>
class base{
public:
void test(T d);
void test2(T* d);
T m_t;
};

template <typename T>
void base<T>::test(T d)
{
m_t = d;
}

template <typename T>
void base<T>::test2(T* d)
{
d = m_t;
}

int _tmain(int argc, _TCHAR* argv[])
{
base<char*> obj;
char** p = NULL;
obj.test("abc");
obj.test2(p);
cout << p <<endl;
return 0;
}


[解决办法]
void base<T>::test2(T* d)
{
    d = m_t;
}

改成
void base<T>::test2(T** d)
{
    *d = m_t;
}

热点排行