I'll try to keep it brief. When I try to pass the 'list' vector to the counter function my compiler throws an error of: "error: request for member size in count, which is of non-class type std::vector<int>*"

Googling hasn't produced anything quite what I'm looking for syntax wise. If someone could enlighten me I'd be most appreciative.

My compiler is g++ version 4.6.3.

#include <iostream>
#include <vector>

using namespace std;

void counter(vector<int> count[]);

int main (){    
        vector<int> list[5];
        counter(list);

        return 0;
}

void counter(vector<int> count[]){
        int i, j=0;

        for(i = 0; i <= count.size(); i++){
                j++;
        }

        cout << "There are " << j << " elements.\n";
}

You can't pass the vector as an array.. Your problem is here:

void counter(vector<int> count[]);

Do this:

void counter(vector<int> &count); // sending reference

Also, you can't allocate memory for a vector like this:

vector<int> list[5];

Instead you can do this:

vector<int> list(5, 0); // size of 5, pushes back 0's

Here, the code:

#include <iostream>
#include <vector>

using namespace std;

void counter(vector<int> &count);

int main (){    
        vector<int> list(5, 0);
        counter(list);

        return 0;
}

void counter(vector<int> &count){
        int i, j=0;

        for(i = 0; i <= count.size(); i++){
                j++;
        }

        cout << "There are " << j << " elements.\n";
}

Hope this helps :)

Wow, your response has been tremendously helpful. Thank you!

No problem :)!

Please mark this as solved, if you have any more questions feel free to ask / post! Good luck

Woops, done. Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.