This Single Inheritance code has no error but when I run this void the function void B::get_ab() gets executed first as expected but the line which is second in the function(cin>>a>>b;) gets executed first and the first line, anyone know whats happening here? Thank you!
#include<iostream>
#include<stdio.h>
using std::equal_range;
using std::lower_bound;
using std::upper_bound;
using std::pair;
using std::string;
using std::getline;
using std::vector;
using std::cout;
using std::ios;
using std::set;
using std::cin;
class B
{
int a;
public: int b;
void get_ab();
int get_a(void);
void show_a(void);
};
class D:private B{
int c;
public: void mult();
void display();
};
void B::get_ab()
{
cout<<"Enter values of a&b";
cin>>a>>b;
}
int B::get_a()
{
return a;
}
void B::show_a()
{
cout<<"a="<<a<<"\n";
}
void D::mult()
{
get_ab();
c=b*get_a();
}
void D::display()
{
show_a();
cout<<"b="<<b<<"\n"<<"c="<<c<<"\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
D d;
d.mult();
d.display();
return 0;
}```
Aucun commentaire:
Enregistrer un commentaire