472,328 Members | 1,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 2262
* 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...
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: "...
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...
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...
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...
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....
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?...
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...
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:...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.