By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

problem in understanding the concept of function overloading in inheritence?

P: 96
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. class A {}; 
  3. class B {}; 
  4.  
  5. class X 
  6. public: 
  7.     void spray(A&) 
  8.     { 
  9.         cout << "Class A" << endl; 
  10.     } 
  11. }; 
  12.  
  13. class Y : public X 
  14.  
  15. public: 
  16.  
  17.     void spray(B&) 
  18.     { 
  19.         cout << "Class B" << endl; 
  20.     } 
  21. }; 
  22.  
  23. int main() 
  24.     A a; 
  25.     B b; 
  26.     Y y; 
  27.  
  28.    y.spray(a);-->complilation error
  29.     y.spray(b); 
  30.  
  31.     return 0; 
  32.  
in the above code why the complilation error comes , in case of inheritence the function of base class should inherited in the derived class so the method will be call of base class through derived class object.
please tell me why this compilation error comes in this code & how to reslove this problem?
plz explain in detail........
thank you
Oct 16 '10 #1
Share this Question
Share on Google+
1 Reply


Markus
Expert 5K+
P: 6,050
See this for some info.
Oct 17 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.