I have been reading on the forum many times before but today I cannot figure out why I am having an error in my code so if anyone can point out to why I am getting these errors I would be thankful. I am new to template and do not understand why vectr is being declare more than once here. I tried to declare vectr globally to fix the error but I do not feel that is the correct fix.
main.cpp:8:31: error: invalid declarator before _v_class printContent (vector<T> v)
^
main.cpp:8:31: error: expected _)_ before _v_
main.cpp: In function _int main()_:
main.cpp:70:23: error: conflicting declaration _printContent vectr_printContent(vectr);
^
main.cpp:49:20: error: _vectr_ has a previous declaration as _std::vector<double> vectr_
vector<double> vectr;
Here are my codes, the goal is to run length encode the contents of a vector to a new vector so that the new vector would have pairs of the number of the items in the old vector plus the item. I will swap the new vector out after I manage to create it inside of this function.
#include <iostream>
#include "vector"
using namespace std;
template<class T>
class printContent (vector<T> v) //Error 31 here
{
vector<pair<int, T> > vp; //declare a new vector with type T
...(Here vectr would go through a loop and vp would fill up with pairs, for now I will also print out the content of the new vector here instead of swapping it out.)
}
int main()
{
vector<double> vectr; //Error 49
/*... (I fill in vectr with various numbers here, could be char or int if I declare vectr to be char or int instead)*/
printContent(vectr); //Error 70
}