473,394 Members | 1,746 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.

[lame] overloaded fun. virt. and inherity


Hi,
I have base class that defines function 'fun'. This function is overloaded
- it can be used fr argument int or for const char* Function is virtual.

Now I create a dervied class cB, and I create new definitions of both
cB::fun - cB::fun(int) and cB::fun(const char*) - all is o.k.

but - now I decided that function cB::fun(const char*) is same as from
cA, so I change it's body to :

cB::fun(const char* s) { cA::fun(s); }

(all is stil ok) - and finaly I commented out the cB::fun(const char* s)
function, so that inherit mechanizm can take care of it. But then -
compiler acts like thar is no cB::fun(const char* s);

problem when using this classes :
class cA {
public:
cA(){};
virtual void fun(int v) { ... }
virtual void fun(const char* v) { ... }
};
class cB : public cA {
public:
cB(){};
virtual void fun(int v) { gConsole->Print("cB-int\n"); }
// !!! virtual void fun(const char* v) { ... }
void xxx() { ... }
};
cB *p = new cB;
p->xxx(); // ok
p->fun(3); // ok
cA->fun("a"); // compiler error - it doesn't see cB::fun(const char*)
// ant therefore it tries to convert const char* into 'int' and call
// cB::fun(int), instead of calling inherited cA::fun(const char*)

((cA*)p)->fun("a"); // this do work "manualy"

cB b;
b.fun("a"); // same compiler error
currently I use a workaround

void cB::fun(const char* v) { cA::fun(v); }

so i'm manualy calling cA's version of fun() instead of just inheriting it
but it's only a (bad) workaround

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~l-.~~~~~~~~~~~~~~~~~~~
GG-1175498 ____| ]____,
Rafal 'Raf256' Maj X-( * )
Rafal(at)Raf256(dot)com ,"----------"
Jul 19 '05 #1
2 1922

"Rafal 'Raf256' Maj" <sp**@raf256.com> wrote in message news:Xn**********************@213.180.128.20...
(all is stil ok) - and finaly I commented out the cB::fun(const char* s)
function, so that inherit mechanizm can take care of it. But then -
compiler acts like thar is no cB::fun(const char* s);

You don't understand inheritance. Only the name is inheritted. None
of the cA::fun definitions appear in cB because the cB::fun definition
hides them.

Add
using cA::fun;
to cB to bring forward the definitions from there.
cA->fun("a"); // compiler error - it doesn't see cB::fun(const char*)
// ant therefore it tries to convert const char* into 'int' and call
// cB::fun(int), instead of calling inherited cA::fun(const char*)


It doesn't see cB::fun because there is no cB fun.

Non-static member calling works like this:

1. The name is looked up (yielding cB::fun)
2. Possible overloads for the name are considered (there is only one cB::fun(int))
3. Access is checked (ok, public)
4. Virtual substitution occurs.
Jul 19 '05 #2
Rafal 'Raf256' Maj wrote:
Hi,
I have base class that defines function 'fun'. This function is overloaded
- it can be used fr argument int or for const char* Function is virtual.

Now I create a dervied class cB, and I create new definitions of both
cB::fun - cB::fun(int) and cB::fun(const char*) - all is o.k.

but - now I decided that function cB::fun(const char*) is same as from
cA, so I change it's body to :

cB::fun(const char* s) { cA::fun(s); }

(all is stil ok) - and finaly I commented out the cB::fun(const char* s)
function, so that inherit mechanizm can take care of it. But then -
compiler acts like thar is no cB::fun(const char* s);

problem when using this classes :
class cA {
public:
cA(){};
virtual void fun(int v) { ... }
virtual void fun(const char* v) { ... }
};
class cB : public cA {
public:
cB(){};
using cA::fun;
virtual void fun(int v) { gConsole->Print("cB-int\n"); }
// !!! virtual void fun(const char* v) { ... }
void xxx() { ... }
};
=


Jul 19 '05 #3

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

Similar topics

8
by: Nitin Bhardwaj | last post by:
Thanx in advance for the response... I wanna enquire ( as it is asked many a times in Interviews that i face as an Engg PostGraduate ) about the overloading capability of the C++ Language. ...
1
by: masood.iqbal | last post by:
I have a few questions regarding overloaded typecast operators and copy constructors that I would like an answer for. Thanks in advance. Masood (1) In some examples that I have seen...
44
by: bahadir.balban | last post by:
Hi, What's the best way to implement an overloaded function in C? For instance if you want to have generic print function for various structures, my implementation would be with a case...
3
by: cybertof | last post by:
Hello, Is it possible in C# to have 2 overloaded functions with - same names - same parameters - different return type values If no, is it possible in another language ?
8
by: Dennis | last post by:
I am trying to decompress MP3 files to WAV using VB.Net. What I really need is a wrapper in VB.Net or C# that includes ALL of the Lame.Dll funcitons including those to decompress to a WAV File. ...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
1
by: Harlin Seritt | last post by:
Is there any type of lame_enc.dll wrapper for Python that's available? Thanks, Harlin Seritt
1
by: Erik Jones | last post by:
So, I was just taking a look at doctest.py and saw this: Then running the module as a script will cause the examples in the docstrings to get executed and verified: python M.py This won't...
2
by: =?Utf-8?B?anVhbg==?= | last post by:
Hello: I have tried for weeks to use LAME in Windows. Can somebody tell me how to do it? I can't add a reference to the project (Visual Basic 2005). Thanks.
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.