Source Code
#include <iostream> using namespace std; class A { private: long int a; public: long int b,x; void set_a(){ cout<<"Enter variable A's value (integer) \nAnswer: "; cin>>a; x=a; } void display_a(){ cout<<"\n value for Variable A: "<<x<<endl; } void getdata(){ cout<<"Enter variable B's value (integer) \nAnswer: "; cin>>b; } }; class B:public A { private: long int prod; public: void prod(){ prod = x*b; } void display(){ cout<<"Displaying product of variables A and B \nProduct: "<<prod<<endl; } }; int main() { A obj; B obj2; obj.set_a(); obj.display_a(); obj2.display(); } Complier Error Message
37 | } | ^ main.cpp:31:16: note: previous declaration ‘long int B::prod’ 31 | long int prod; | ^~~~ I have just started learning Inheritance functions from Object Oriented programming so I am quite the novice. I believe the program lies within the Inheritance function sub class but I am not too sure.
Also, I am pretty sure there is a method to checking the solution to error messages from the compiler but I don't know what it is or where to look, so some assistance would be helpful
prodwith the exact same name as a data member. Also - better to avoidusing namespace std- see here stackoverflow.com/questions/1452721/….