Hello everyone!
I'm new here, also new in c++ programing, so I have problem. I'll post code here, then I gonna explain a situation...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include<iostream>
#include<vector>
using namespace std;
template<class T>
void InputVector(vector<T>a)
{
cout<<"input 5 elements of vector"<<endl;
for (int i=0;i<5;i++)
{
cin>>a[i];
cout<<endl;
}
};
template<class T>
void OutputVector(vector<T> &a)
{
cout<<"-----ELEMENTS-----"<<endl;
vector<T>::iterator ITERATOR;
for (ITERATOR=a.begin();ITERATOR<a.end();ITERATOR++)
{
cout<<*ITERATOR<<endl;
}
};
void main ()
{
vector<int> a(5);
InputVector(OutputVector(a));
}
|
As you can see, I want to have one template for input elements of vector, and one template for output, to print elements.
When I build this, there is showing a error:
Error 1 error C2784: 'void InputVector(std::vector<T>)' : could not deduce template argument for 'std::vector<T>' from 'void'
I was trying on other way, to change void main in next style:
1 2 3 4 5 6
|
void main ()
{
vector<int> a(5);
InputVector(a);
OutputVector(a);
}
|
So, when I build like that, it has no errors, but it doesn't print my elements.
Can somebody help to me?I hope that you can understand what I'm trying to do.
Thanks!