0

Why is the compiler giving an error???

#include <iostream> using namespace std; class Human { int cnic; int age; public: int setdata(int ,int );/*{ a= cnic; b=age; }*/ void getdata(){ cout<<"My CNIC is "<<cnic<<endl; cout<<"My age is "<<age<< endl; } }; int Human::setdata(int a,int b){ a= cnic; b=age; } class student :public Human{ int rollno; int section; public: int setdata(int x ,int y){ x=rollno; y=section; } void getdata(){ cout<<"My roll no. is "<<rollno<<endl; cout<<"My section is "<<section<<endl; } }; class Employee :public Human{ string name; int id; public : int setdata(string ,int );/*{ o1=name; o2=id; }*/ void getdata(){ cout<< "Employee ID is "<<id <<endl; cout<<"Employee name is "<<name<<endl; } }; int Employee ::setdata(string o1 ,int o2){ o1=name; o2=id; } int main() { Human h; h.setdata(123,34); h.getdata(); return 0;

28th Feb 2024, 12:51 AM
Haram Abbas Lar
Haram Abbas Lar - avatar
2 ответов
+ 2
setters should have void return type. Also you have arguments and variables reversed.
28th Feb 2024, 4:27 AM
Bob_Li
Bob_Li - avatar
+ 2
#include <iostream> using namespace std; class Human { int cnic; int age; public: void setdata(int a, int b){ cnic = a; age = b; } void getdata(){ cout<<"My CNIC is "<<cnic<<endl; cout<<"My age is "<<age<< endl; } }; class Student :public Human{ int rollno; int section; public: void setdata(int x ,int y){ rollno = x; section = y; } void getdata(){ cout<<"My roll no. is "<<rollno<<endl; cout<<"My section is "<<section<<endl; } }; class Employee :public Human{ string name; int id; public : void setdata(string o1 ,int o2){ name = o1; id = o2; } void getdata(){ cout<< "Employee ID is "<<id <<endl; cout<<"Employee name is "<<name<<endl; } }; int main() { Human h; h.setdata(123,34); h.getdata(); Student s; s.setdata(30,5); s.getdata(); Employee e; e.setdata("Shamir", 455); e.getdata(); }
28th Feb 2024, 4:29 AM
Bob_Li
Bob_Li - avatar