the member functionproblem
I have written this program
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
|
#include<iostream>
#include<string>
using namespace std;
class person{
string m;
public:
void getdata(void);
void display(void);
};
person :: void getdata(void)
{ cout<<"Emter person name";
getline(cin,m);
}
person:: void display(void)
{
cout<<"The person"<<m;
}
int main()
{
person b;
b.getdata();
b.dispaly();
return 0;
}
|
but it shows eorror..Why?
1 2 3 4 5 6 7 8 9 10
|
person :: void getdata(void)
{ cout<<"Emter person name";
getline(cin,m);
}
person:: void display(void)
{
cout<<"The person"<<m;
}
|
|
it should be:
1 2 3 4 5 6 7 8 9 10
|
void person :: getdata(void)
{ cout<<"Emter person name";
getline(cin,m);
}
void person :: display(void)
{
cout<<"The person"<<m;
}
|
and in line 19 (a grammatical error):Enter not Emter
Also,
void is not needed in C++ to signify empty parameter list.
It is only needed for this purpose in C.
1 2 3 4 5 6 7 8 9 10
|
void person::getdata()
{
cout << "Enter person name ";
getline(cin, m);
}
void person::display()
{
cout << "The person " << m;
}
|
oh thanks,.. Yes Typing error..I am not so good at that
However i have tried toi fix it but it shows
1 2 3 4 5 6 7 8
|
int main()
{
person b;
b.getdata();
b.dispaly(); //this is b.display
return 0;
}
|
Topic archived. No new replies allowed.