c++ - Run length encoding a vector error -
i have been reading on forum many times before today cannot figure out why having error in code if can point out why getting these errors thankful. new template , not understand why vectr beingness declare more 1 time here. tried declare vectr globally prepare error not sense right 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 previous declaration _std::vector<double> vectr_ vector<double> vectr;
here codes, goal run length encode contents of vector new vector new vector have pairs of number of items in old vector plus item. swap new vector out after manage create within of 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 new vector type t ...(here vectr go through loop , vp fill pairs, print out content of new vector here instead of swapping out.) } int main() { vector<double> vectr; //error 49 /*... (i fill in vectr various numbers here, char or int if declare vectr char or int instead)*/ printcontent(vectr); //error 70 }
thank help.
not sure if want template class or looking function print vector? here code reworked compile.
source
#include <vector> #include <utility> using namespace std; template< class t > class printcontent { public: printcontent( vector< t > value ) { //make vector of pairs here. } private: vector< pair< int, t > > m_values; }; int main( int, char** ) { vector< double > value; printcontent< double > object( value ); homecoming 0; }
build
g++ -o homework homework.cpp
c++ templates vector declaration pair
No comments:
Post a Comment