Link list using STL related problems

Can any body help me ... i am facing problem in passing list<string> to simple function. here is the code
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
30
31
32
33
34
35
36
//  called in main as 
void main(){
	int const SIZE = 11;
	list<string> *table[SIZE];

	for(int i=0 ; i<SIZE ; i++)
		table[i] = NULL;

	input(table);
}
void input(list<string> *x[]){

	int count = 0;	cout<<"count : ";	cin>>count;

	cout<<"Enter Names ";	string buffer;

	for(int i=0 ; i<count ; i++)
	{
		cin>>buffer;
		int key = keyGenerator(buffer);
		// insertion
		if(x[key]!=NULL)
		{
			cout<<"collision Occured"<<endl;
			x[key]->push_back(buffer);
		}
		else
		{
			x[key] = new list<string>;
			x[key]->push_back(buffer);
		}
	}



}


error is -> e:\projects\dictionary\dictionary\main.cpp(17): error C2664: 'input' : cannot convert parameter 1 from 'std::list<_Ty> *[11]' to 'std::list<_Ty>'


any help would be apprecited
Change the declaration that you aren't showing here to match the definition.
i declared it as
list<string> *table[SIZE];
and wanted to pass by ref
void input(list<string>& *x[])

is this correct now .. ?
Somewhere above main you had:

void input(list<string> x);

Change that to match the definition of the function.
Last edited on
yes i know it very well that both the definition should match.

but still the i m facing the error massage . here is the full code.

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <list>
#include <string>

using namespace std;

int keyGenerator(string);

void input(list<string>& *x[]){

	int count = 0;	cout<<"count : ";	cin>>count;

	cout<<"Enter Names ";	string buffer;

	for(int i=0 ; i<count ; i++)
	{
		cin>>buffer;
		int key = keyGenerator(buffer);
		// insertion
		if(x[key]!=NULL)
		{
			cout<<"collision Occured"<<endl;
			x[key]->push_back(buffer);
		}
		else
		{
			x[key] = new list<string>;
			x[key]->push_back(buffer);
		}
	}




}

void main(){
	int const SIZE = 11;
	list<string> *table[SIZE];

	for(int i=0 ; i<SIZE ; i++)
		table[i] = NULL;

	input(table);

for(int i=0,j=0 ; i<SIZE ; i++)
	{
		if(table[i]!=NULL)
		{
			cout<<"the "<<j+1<<" value is "<<table[i]->front()<<endl;
			j++;
		}
	}
}


int keyGenerator(string str){	int sum = 0;

	string::iterator x = str.begin();

	for(int i=0 ; i<str.length() ; i++)
		sum += static_cast<int>(*x);

	return sum%11;
}


i m using it as an inline function.
What you say you want: void input(list<string>* (&x)[11])

What you actually need: void input(list<string>* x[])





thanks for helping bro ... problem solved by using the
list<string> **object;
Topic archived. No new replies allowed.