473,394 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

inheritance / overloading

suppose i've got the following:

class a {
public:
virtual void f(int a);
};

class b : public a {
public:
void f(int a, int b);
};

Now I expected that if I had an object o of type b and I would call
o.f(1); that the method of class a would be invoked. However, if I try
this, the compiler says 'b::f does not take one parameter' (msvc++ 2005
beta 2).

How can I solve this? I want o.f(1) to call the method of a, and o.f(1,
2) to call the method of b.

Thanks in advance,

Maurice Termeer
Jul 22 '05 #1
2 1426

"Maurice Termeer" <m.*********@student.tue.nl> wrote in message
news:ci*********@news.tue.nl...
suppose i've got the following:

class a {
public:
virtual void f(int a);
};

class b : public a {
public:
void f(int a, int b);
};

Now I expected that if I had an object o of type b and I would call
o.f(1); that the method of class a would be invoked. However, if I try
this, the compiler says 'b::f does not take one parameter' (msvc++ 2005
beta 2).

How can I solve this? I want o.f(1) to call the method of a, and o.f(1,
2) to call the method of b.


This is what Comeau online tells me - "warning: function "a::f(int)" is
hidden by "b::f" --virtual function override intended ? Check the FAQ at
http://www.parashift.com for more details on this. To make a::f visible in b
write this -
class b : public a {
public:
using a::f;
^^^^^^^
....
};

Sharad
Jul 22 '05 #2
Sharad Kala wrote:
This is what Comeau online tells me - "warning: function "a::f(int)" is
hidden by "b::f" --virtual function override intended ? Check the FAQ at
http://www.parashift.com for more details on this. To make a::f visible in b
write this -
class b : public a {
public:
using a::f;
^^^^^^^
...
};


thanks! i've never used the using keyword in this context before.. and
that really is a nice reference. too bad i can't download it for offline
viewing anymore.

and quite nice that the problem was listed under "what your mother never
told you" and the whole "it means you're going to die" thing.

Maurice
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fuzzyman | last post by:
I've been programming in python for a few months now - and returning to programming after a gap of about ten years I've really enjoyed learning python. I've just made my first forays into...
1
by: Katie | last post by:
my one base class is a linklist class.now i'd like to inherit it by another class.The problem is that when i use the derived class i can't access the base class's pointers.classic type mismatch.how...
12
by: Steve Jorgensen | last post by:
The classing Visual Basic and VBA support for polymorphism, let's face it, is a bit on the weak side, and built-in support for inheritance is non-existent. This little essay is about some patterns...
6
by: apm | last post by:
Recently I have had to use a value type for a complex structure because I don't know how to override the = operator. Can the operator ever be overloaded? Or can inheritance be used with value types?
10
by: Lino Barreca | last post by:
Take a look at this code: Class clsAnagrafica Public Overridable ReadOnly Property Codice() As Integer Get Return 1 End Get End Property End Class
4
by: Shayne H | last post by:
I have a query about an intricacy of inheritance and overloading. I am coding a class inherited from System.Uri. If I look in the object browser (with hidden members shown) there are 4 overloaded...
6
by: Massimo Soricetti | last post by:
Hello, recently I wrote a little class which has to wrap two different type of data, showing the same external interface. I used operator overloading, but the same result I could eventually...
7
by: =?Utf-8?B?QWxleCBDb2hu?= | last post by:
In C++, there is an easy technique to provide an overloaded Equals() method. A straightforward translation to C# causes a stack overflow. Why does b.Equals(ba) in the snippet below not understand...
17
by: Bart Friederichs | last post by:
Hello, I created the following inheritance: class Parent { public: void foo(int i); }; class Child : public Parent {
3
by: puzzlecracker | last post by:
Are static method inheritable under csharp rules, if so how can they be used? Can they be virtual? They reason I am asking is because operators are static, and I don't understand how can we...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
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...
0
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
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...

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.