473,487 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Overrided Function Causing Problems

sbvishal
6 New Member
Dear All
I am writing a sample code which is causing errors...
Anybody knows why it is happening??
The Code is given below..

class A
{ public:
A()
{
cout<<"Its A"<<endl;
};

virtual show()
{
printf("Check");
printf("A");
}
};
class B : virtual public A
{ public:
B()
{
cout<<"Its B"<<endl;
}
//virtual
virtual show()
{
printf("Check");
printf("B");
}
};
class C:virtual public A
{ public:

C()
{
cout<<"Its C"<<endl;
}
virtual show(int x)
{
cout<<"x="<<endl;
printf("C Calling Show function of Class C\n");
printf("Check");
}
};
class D:virtual public B,virtual public C
{
public:
D()
{
cout<<"Its D"<<endl;
}
/*show()
{
printf("Check");
printf("D");
}*/
};

void main()
{
D obj;
obj.show(5);
getch();
}


And the error is..

warning C4250: 'D' : inherits 'B::show' via dominance : see declaration of 'show'
error C2385: 'D::show' is ambiguous
warning C4385: could be the 'show' in base 'B' of class 'D'
warning C4385: or the 'show' in base 'C' of class 'D'
error C2660: 'show' : function does not take 1 parameters
Feb 3 '08 #1
2 1411
weaknessforcats
9,208 Recognized Expert Moderator Expert
A coupole of things
1) your show() method has no return type. Assuming an int is C and this is deprecated in C++. You need to specify a return type.

2) you cannot overload functions between classes. That is, a show() in a base class cannot be overloaded by a show(int) in a derived class. Overloading means the method name is the same and the arguments are different.

This is OK:
Expand|Select|Wrap|Line Numbers
  1. class A
  2. {
  3.       void show();
  4.       void show(int);
  5. };
  6.  
This is OK but the derived class cannot call show();
Expand|Select|Wrap|Line Numbers
  1. class A
  2. {
  3.     public:
  4.       void show();
  5. };
  6. class B : public A
  7. {
  8.     public:
  9.        void show(int);
  10. };
  11. int main()
  12. {
  13.     B obj;
  14.     obj.show();   //Error: B::Show does not take 0 arguments
  15. }
  16.  
The show(int) dominates the show(). You would have to code:
Expand|Select|Wrap|Line Numbers
  1. main()
  2. {
  3.     B obj;
  4.     obj.A::show();
  5. }
  6.  
Notice that public/private/protected are ignored in dominance. Dominance is based on the function name alone. The local name always dominates inherited names.
Feb 3 '08 #2
sbvishal
6 New Member
Thanks for your reply.
It made many things clear.



A coupole of things
1) your show() method has no return type. Assuming an int is C and this is deprecated in C++. You need to specify a return type.

2) you cannot overload functions between classes. That is, a show() in a base class cannot be overloaded by a show(int) in a derived class. Overloading means the method name is the same and the arguments are different.

This is OK:
Expand|Select|Wrap|Line Numbers
  1. class A
  2. {
  3.       void show();
  4.       void show(int);
  5. };
  6.  
This is OK but the derived class cannot call show();
Expand|Select|Wrap|Line Numbers
  1. class A
  2. {
  3.     public:
  4.       void show();
  5. };
  6. class B : public A
  7. {
  8.     public:
  9.        void show(int);
  10. };
  11. int main()
  12. {
  13.     B obj;
  14.     obj.show();   //Error: B::Show does not take 0 arguments
  15. }
  16.  
The show(int) dominates the show(). You would have to code:
Expand|Select|Wrap|Line Numbers
  1. main()
  2. {
  3.     B obj;
  4.     obj.A::show();
  5. }
  6.  
Notice that public/private/protected are ignored in dominance. Dominance is based on the function name alone. The local name always dominates inherited names.
Feb 11 '08 #3

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

Similar topics

9
4933
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
4
1088
by: jccpro | last post by:
as the following code shows: class A { public: A(const A & rhs) { *this = rhs; } A & operator=(const A & rhs) { if (this != &rhs) {
10
2375
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
0
4477
by: cyrille | last post by:
Hello from example from web i did a little code to avoiding columnHeader resize. this code seems to work well, but when I put a 'normal' ListView on the same Form than my overrided ListView it...
1
2781
by: checcouno | last post by:
I've got MyClassA superclass for MyClassB. In MyClassA there're 2 function f1 and f2. f2 is called from f1. MyClassB specialize MyClassA and, overrides the f2 function. when in MyClassB i call f1...
12
2410
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is...
11
2387
by: Chris Thomasson | last post by:
Consider an an object that that can has 7 or 8 functions. If you create an abstract base class for the "interface" of the object, well, that means 7 or 8 pure virtual functions right? Well, IMHO,...
0
1380
by: Erwin Moller | last post by:
Hi group, I found something strange in PHP5.2.4 (on IIS7/Vista). I am working on an app that has been running just fine under heavy load for over a year at some custumer of mine. (they have...
30
2691
by: Adam | last post by:
Hi, I have a simple printf-like function: int print(const char *format, ...) { char buffer; va_list argptr; int i;
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.