由买买提看人间百态

topics

全部话题 - 话题: elemtype
(共0页)
w******g
发帖数: 67
1
来自主题: Programming版 - C++ template problem
I have a simple C++template code, but I cannot get it run.
In DataTemplate.h:
template
ElemType* getVecElemPointer(int index, vector& vec);
In DataTemplate.cpp:
template
ElemType* getVecElemPointer(int index, vector& vec)
{
if( (index0) )
{
return &vec[index];
}
return (ElemType*) 0;
}
It is fine when I compile it: "g++ -c -g DataTemplate.cpp"
In another class implementation file: test.cpp
#inclu
w******g
发帖数: 67
2
来自主题: Programming版 - C++ question about template typedef
Thanks a lot. Another question: if I want to define a function template to
print out the elements of the MapOfVec.
template
struct MapOfVec
{
typedef vector VecType;
typedef typename vector::iterator VecIter;
typedef map MapType;
typedef typename map::iterator MapIter;
};
template
void printElems_MapOfVec(const MapOfVec::MapType& map);
It a
w******g
发帖数: 67
3
来自主题: Programming版 - C++ template problem
Yes, it works when I put both the declaration and implementation in the head
file, like:
In DataTemplate.h:
template
ElemType* getVecElemPointer(int index, vector& vec)
{
if( (index0) )
{
return &vec[index];
}
return (ElemType*) 0;
}
The linkage works. Can you explain why? Thanks.
G****A
发帖数: 4160
4
来自主题: Programming版 - C++小程序查错
下面这段程序编译没有错误,执行后windows却弹出错误提示框,请帮我看看怎么回事.谢谢
template
void display(const string &msg, const vector &vec)
{
elemType t = vec[0];
cout< cout< }
int main()
{
string a = "Hello";
vector ivec;
ivec[0] = 7;
display(a, ivec);

return 0;
}
B********e
发帖数: 1062
5
来自主题: Programming版 - C++ question about template typedef
template
struct MapofVec{
typedef vector VecType;
typedef typename vector::iterator VecIter;
typedef map MapType;
typedef typename map::iterator MapIter;
};

use
**
B********e
发帖数: 1062
6
来自主题: Programming版 - C++ question about template typedef
This may work.
template
class MapOfVec{
public:
typedef vector VecType;
typedef typename vector::iterator VecIter;
typedef map MapType;
typedef typename map::iterator MapIter;
void print(MapType& map);
};

agian.
w******g
发帖数: 67
7
来自主题: Programming版 - C++ question about template typedef
I have a question about template typedef. The question is that I want to use
the data structure like map>.
So I define the following:
#ifndef DATATEMPLATE_H_
#define DATATEMPLATE_H_
#include
#include
using namespace std;
/***************************************************************************
***********************************
* The following code define the type"MapOfVec"
* Map >
*
* Note: KeyType, ElementType are si
(共0页)