P
PengYu.UT
Hi,
I have the following program which use a template as a template
parameter. But it seems that it doesn't work. Do you know how to make
it work?
Although I can change the lines with comments the comments, but that is
not what I want. Since the only different is for the program is either
use "vector" "stack" ..., I don't want to specify redundant information
"int" overthere.
Best wishes,
Peng
#include <iostream>
#include <vector>
template <typename __Tp>
class A{
public:
A(){};
~A(){};
void push_back(int i){ _vector_int_inst.push_back(i);}
void show(){
copy(_vector_int_inst.begin(), _vector_int_inst.end(),
ostream_iterator<int>(s
td::cout, "\n"));
}
private:
__Tp<int> _vector_int_inst;//__Tp _vector_int_inst;
};
int main(int argc, char *argv[])
{
A<std::vector> a;//A<std::vector<int> > a;
a.push_back(1);
a.push_back(2);
a.show();
}
I have the following program which use a template as a template
parameter. But it seems that it doesn't work. Do you know how to make
it work?
Although I can change the lines with comments the comments, but that is
not what I want. Since the only different is for the program is either
use "vector" "stack" ..., I don't want to specify redundant information
"int" overthere.
Best wishes,
Peng
#include <iostream>
#include <vector>
template <typename __Tp>
class A{
public:
A(){};
~A(){};
void push_back(int i){ _vector_int_inst.push_back(i);}
void show(){
copy(_vector_int_inst.begin(), _vector_int_inst.end(),
ostream_iterator<int>(s
td::cout, "\n"));
}
private:
__Tp<int> _vector_int_inst;//__Tp _vector_int_inst;
};
int main(int argc, char *argv[])
{
A<std::vector> a;//A<std::vector<int> > a;
a.push_back(1);
a.push_back(2);
a.show();
}