473,837 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with overloaded virtual function

Hi all,
I am trying to compile following code :-
=============== =============== =========
#include <iostream.h>
#include <string>
namespace tlm
{
template <typename REQUEST, typename RESPONSE >
class tlm_transport_i f
{
public:
// Virtual function: for implementation of transport layer
virtual RESPONSE transport (const REQUEST &) = 0;
}; // end of class tlm_transport_i f

}

class master_out_if
{
private:
class inherit: public tlm::tlm_transp ort_if<int,bool >,
public tlm::tlm_transp ort_if<char,boo l >,
public tlm::tlm_transp ort_if<double,b ool >
{};
public:
typedef inherit type;
};
class x:public master_out_if:: type
{
public:
bool transport (const int&){}
bool transport (const char &){}
bool transport (const double &){}

};

int main()//this can be bus model

{
bool var;
master_out_if:: type *var1=new x;
var1->transport((int )(100));

}
=============== =============== ============
The problem is that I get a compile time error which says

-----------------------------------------------------------
test2.cpp: In function `int main()':
test2.cpp:55: cannot allocate an object of type `x'
test2.cpp:55: because the following virtual functions are abstract:
test2.cpp:13: RESPONSE tlm::tlm_transp ort_if<REQUEST,
RESPONSE>::tran sport(const REQUEST&) [with REQUEST = double, RESPONSE =
bool]
test2.cpp:56: request for member `transport' is ambiguous
test2.cpp:13: candidates are: RESPONSE tlm::tlm_transp ort_if<REQUEST,
RESPONSE>::tran sport(const REQUEST&) [with REQUEST = double, RESPONSE =
bool]
test2.cpp:13: RESPONSE tlm::tlm_transp ort_if<REQUEST,
RESPONSE>::tran sport(const REQUEST&) [with REQUEST = char, RESPONSE =
bool]
test2.cpp:13: RESPONSE tlm::tlm_transp ort_if<REQUEST,
RESPONSE>::tran sport(const REQUEST&) [with REQUEST = int, RESPONSE =
bool]
--------------------------------------------------------------------
Does that mean overloading of virtual functions is not allowed?. If not how
I can implement this functionality
Abhishek


Jul 22 '05 #1
1 2345
* A. Saksena:
Hi all,
I am trying to compile following code :-
=============== =============== =========
#include <iostream.h>
ERROR. Don't use <iostream.h>.

It's is a pre-standard header that's not part of standard C++.

Use standard

#include <iostream>

BAD STYLE. Don't include headers that you don't use.

#include <string>
BAD STYLE. Don't include headers that you don't use.

namespace tlm
{
template <typename REQUEST, typename RESPONSE >
BAD STYLE. Don't use all uppercase for non-macro names.

class tlm_transport_i f
BAD STYLE. Don't use the namespace name as prefix for things declared
in the namespace -- the namespace provides a good enough prefix.

BAD STYLE. Don't use inconsistent indentation.
{
public:
// Virtual function: for implementation of transport layer
virtual RESPONSE transport (const REQUEST &) = 0;
}; // end of class tlm_transport_i f

} class master_out_if
{
private:
class inherit: public tlm::tlm_transp ort_if<int,bool >,
public tlm::tlm_transp ort_if<char,boo l >,
public tlm::tlm_transp ort_if<double,b ool >
{};
public:
typedef inherit type;
BAD STYLE. Don't use silly roundabout ways. If you mean the nested
class to be public, declare it public in the first place.
};
class x:public master_out_if:: type
{
public:
bool transport (const int&){}
ERROR. The function must return a value.

bool transport (const char &){}
bool transport (const double &){}

};

int main()//this can be bus model

{
bool var;
BAD STYLE. Don't declare variables that you don't use.

master_out_if:: type *var1=new x;
var1->transport((int )(100));

}
=============== =============== ============
The problem is that I get a compile time error [...]

Does that mean overloading of virtual functions is not allowed?.
It means that when you have same-named identifiers in different
subobjects (here base class subobjects), the name look up fails:
function signatures are not considered at that point.

If not how I can implement this functionality


Add a 'using' for each function in class 'master_out_if: :type'.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2

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

Similar topics

12
3726
by: Victor Chew | last post by:
Can someone tell me why the following code doesn't work: > TestClass.cpp > ------------- > class A > { > public: > virtual void read(wchar_t& ch) { read(&ch, 0, 1); } > virtual void read(wchar_t* buf, int off, int len) = 0; > };
3
1713
by: N4M | last post by:
Dear, I have problems with overloaded operators ++() and --(). MSVC++ 6.0 compiler gives errors, one is shown as below: " c:\data\c++\mygraphs\graph.h(182) : error C2555: 'CGraphNodeIter::++' : overriding virtual function differs from 'CGraphNodeIterI::++' only by return type or calling convention c:\data\c++\mygraphs\graph.h(141) : see declaration of 'CGraphNodeIterI' "
4
2412
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a hierarchy of algebraic matrices with the addition operation. Thus, I want to have a virtual base class class Matr;
1
2230
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 pertaining to casting class A to class B, the implementation of the
20
2900
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
2
2027
by: gg | last post by:
I am facing some problems with following program. I am using aCC version 03.27 on HP-UX11. The command line I use to compile is - aCC -AA -I. TestTempMethods.C Can anybody pls suggest how to resolve the warnings and errors. #include <iostream> using namespace std;
3
7142
by: PengYu.UT | last post by:
The following program shows that virtual function can not be overloaded. Could you tell me the reasons from the C++ compiler point of view? Thanks! Peng #include <iostream>
6
2279
by: Bit byte | last post by:
I have a class BaseApplication, from which I am deriving two classes A and B. In class BaseApplication, I have a virtual method as ff: virtual void saveToDb(const char*); I will like to overload this function in A and B, because I want to have the ff (for example)
11
3068
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
0
9696
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10583
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10288
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7824
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4481
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.