0

can anyone help?

what's wrong in this code? i want to print teacher sub,publication,name,id using inheritance but it tells me wrong why? https://code.sololearn.com/csFnO6gq6VYH/?ref=app

17th Oct 2019, 8:32 PM
Mohammed Raihan
Mohammed Raihan - avatar
19 Respostas
+ 6
rakib.id=1012; ID is not yet a property of one of the objects. if you want a teacher, you need to declare one. staff rakib; // rakikb is a staff member teacher t1; //t1 is a teacher, this object does have the property pub char is just one character since you have referenced std, you can use "string" to declare the name
17th Oct 2019, 8:58 PM
sneeze
sneeze - avatar
+ 3
You need to write you code in the playground first before you can show it https://code.sololearn.com/c19CQV3zNo9p.
17th Oct 2019, 8:55 PM
sneeze
sneeze - avatar
+ 3
found the solution... thank you guys.. actually i'm new in solo...
17th Oct 2019, 8:57 PM
Mohammed Raihan
Mohammed Raihan - avatar
+ 2
If you want to post long codes, please write it in code playground and then share it here. Plain text is harder to read.
17th Oct 2019, 8:43 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Click on edit post, there should be a + sign at the bottom, click on it and select 'insert code'
17th Oct 2019, 8:50 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Okay, the problem in your code is that your class has no member named id, code...etc. you must first define them inside your class before assigning them
17th Oct 2019, 8:55 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
ok.. thanks for advising..
17th Oct 2019, 8:44 PM
Mohammed Raihan
Mohammed Raihan - avatar
+ 1
but how i could share my code here?
17th Oct 2019, 8:48 PM
Mohammed Raihan
Mohammed Raihan - avatar
+ 1
done
17th Oct 2019, 8:52 PM
Mohammed Raihan
Mohammed Raihan - avatar
+ 1
oh.. now it make sense.. thank you
17th Oct 2019, 9:01 PM
Mohammed Raihan
Mohammed Raihan - avatar
+ 1
Welcome in Sololearn, Keep asking, Keep Coding. Have fun in the playground.
17th Oct 2019, 9:02 PM
sneeze
sneeze - avatar
0
😂
19th Oct 2019, 8:24 AM
Ahmad Zia
Ahmad Zia - avatar
0
You using int main so in last use return zero ok
19th Oct 2019, 9:06 AM
Deepak Singh
Deepak Singh - avatar
0
ممكن احد يشرح لي البرنامج 👀
19th Oct 2019, 9:25 AM
راكان
راكان - avatar
0
Check id variable
19th Oct 2019, 9:59 AM
Jadhav Shrikrushna Dnyaneshwar
Jadhav Shrikrushna Dnyaneshwar - avatar
0
#include<iostream> #include<conio.h> using namespace std; class staff{ public: // char name; string name; int code; int pub; void display1(){ cout<<name<<endl; cout<<code<<endl; } }; class teacher:public staff { public: int pub; char sub; void display2(){ cout<<pub<<endl; cout<<sub<<endl; display1(); } }; class officer:public staff { char grade; void display3(){ cout<<grade<<endl; } }; int main(){ cout << "print staff"<<endl; staff rakib; //rakib.id=1012; rakib.code=222; rakib.pub=04; // rakib.sub="eee"; rakib.name="hasan_rakib"; rakib.display1(); //getch(); cout << "print teacher"<<endl; teacher t1; t1.code=333; t1.pub=04; t1.sub='e'; t1.name="hakim"; t1.display1(); t1.display2(); //getch(); }
19th Oct 2019, 3:45 PM
Abhishek wadalkar
Abhishek wadalkar - avatar
0
hi
19th Oct 2019, 6:08 PM
Õõ Lãý Tĥãñt
Õõ Lãý Tĥãñt - avatar
0
Glad to see yo
19th Oct 2019, 6:10 PM
Õõ Lãý Tĥãñt
Õõ Lãý Tĥãñt - avatar
- 1
Hi
19th Oct 2019, 11:51 AM
Nina Balva
Nina Balva - avatar