Error in function call of search function..Urgent!!

Error in long kitti=B.search(s,no,B); line....I have no idea ...Pls help..urgent!!
I have an examination due tomorrow

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
66
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class batsmen
{
 public:
 long search(long sno,int size,long bno[]);
 int age;
 long bno,sno;
 char name[30],country[20];
 void getdata()
 {
  cout<<"Enter batsman number:";
  cin>>bno;
  cout<<"\nEnter batsman name:";
  gets(name);
  cout<<"Enter country:";
  gets(country);
  cout<<"\nEnter age:";
  //cin>>age;
 }
 void putdata()
 {
  cout<<"Batsman Number "<<bno;
  cout<<"Batsman Name : ";
  puts(name);
  cout<<"Country : ";
  puts(country);
  cout<<"Age : "<<age;
 }
};
void main()
{
 long s;
 int no;
 batsmen B[20];
 cout<<"Enter the number of batsmen:";
 cin>>no;
 for(int i=0;i<no;i++)
 {
  cout<<"Enter the details of batsman "<<(i+1)<<" : ";
  B[i].getdata();
 }
 cout<<"Enter the number of the batsman who is to be searched for:";
 cin>>s;
 long kitti=B.search(s,no,B);
 clrscr();
 cout<<"Details of "<<kitti<<" : ";
 B[kitti].putdata();
 getch();
}
long batsmen::search(long sno,int size,long bno[])
{
 int beg=0,last=size-1,mid;
 while(beg<=last)
 {
  mid=(beg+last)/2;
  if(sno==bno[mid])
	return mid;
  else if(sno>bno[mid])
	beg=mid+1;
  else
	last=mid-1;
 }
 return -1;
}

Dude... B is an array, you gotta do B[?].search(...);.
@poteto, I know that. But I don't know what comes after B[ in B[?].search(...);
Make the search function static:
1
2
3
4
5
class batsmen
{
 public:
 static long search(long sno,int size,batsmen bno[]); // Note the last parameter
...

line 46: long kitti=batsmen::search(s,no,B);

Note that in batsmen::search: if(sno==bno[mid].bno) // bno[] is the class etc.
Topic archived. No new replies allowed.