c++ - Run length encoding a vector error -
I was reading several times earlier on stage, but today I did not know why there is a problem in my code if someone It can tell if I am receiving these errors and I am grateful. I'm new to the template and I do not understand why vectr is being declared more than once, I tried to declare the vectr globally to fix the error but I do not think this is the right fix is.
main.cpp: 8: 31: error: _v_class before the printcontent invalid declarator (vector T> V) ^ main.cpp: 8: 31: error: expected _ } _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ '_': Error: conflicting declaration _print content vectr_printContent (vectr); ^ Main.cpp: 49: 20: Error: The previous declaration in _vectr_ is _std :: vector & lt; Double & gt; Vectr_ vector & lt; Double & gt; Vectr; These are my code, to run the target length, the content of a vector is to be encoded in a new vector so that the new vector has the number of objects in the old vector. After creating this item within the plus item, I will swap the new vector.
#include & lt; Iostream & gt; # Include "vector" using the namespace std; Template & lt; Class T & gt; Class print content (vector & lt; T & gt; v) // error 31 here {vector & lt; Pair and lieutenant; Int, T & gt; & Gt; Vice President; // declare a new vector with Type T ... (Here vectr will go through a loop and VP will be filled with joints, because now I will print the contents of the new vector instead of vector it. }} Int main () {Vector & lt; Double & gt; Vectr; // Error 49 / * ... (I fill vectr with different numbers, can be four or int if i declare vectr as four or integer) * / printContent (vectr); // Error 70} Thank you for your help.
Not sure whether you want the template class or the actual function to print the vector Looking for? Here your code has been redone for compiling.
Sources #include & lt; Vector & gt; # Include & lt; Utility & gt; using namespace std; The template's & lt; Class T & gt; Class printcontent {public: print content (vector & lt; T & gt; value) {// pairs of vector make here. } Private: Vector & lt; Pair of & lt; Int, T & gt; & Gt; M_values; }; Int main (int, char **) {vector & lt; Double & gt; value; PrintContent & LT; Double & gt; Object (value); Return 0; } build G ++ Home HomePaper
Comments
Post a Comment