473,473 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Create 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_if
{
public:
// Virtual function: for implementation of transport layer
virtual RESPONSE transport (const REQUEST &) = 0;
}; // end of class tlm_transport_if

}

class master_out_if
{
private:
class inherit: public tlm::tlm_transport_if<int,bool >,
public tlm::tlm_transport_if<char,bool >,
public tlm::tlm_transport_if<double,bool >
{};
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_transport_if<REQUEST,
RESPONSE>::transport(const REQUEST&) [with REQUEST = double, RESPONSE =
bool]
test2.cpp:56: request for member `transport' is ambiguous
test2.cpp:13: candidates are: RESPONSE tlm::tlm_transport_if<REQUEST,
RESPONSE>::transport(const REQUEST&) [with REQUEST = double, RESPONSE =
bool]
test2.cpp:13: RESPONSE tlm::tlm_transport_if<REQUEST,
RESPONSE>::transport(const REQUEST&) [with REQUEST = char, RESPONSE =
bool]
test2.cpp:13: RESPONSE tlm::tlm_transport_if<REQUEST,
RESPONSE>::transport(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 2331
* 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_if
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_if

} class master_out_if
{
private:
class inherit: public tlm::tlm_transport_if<int,bool >,
public tlm::tlm_transport_if<char,bool >,
public tlm::tlm_transport_if<double,bool >
{};
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
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...
3
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::++' :...
4
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...
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...
20
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
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...
3
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
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...
11
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
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...
1
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...
0
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.