469,898 Members | 1,790 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

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 2162
* 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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Victor Chew | last post: by
3 posts views Thread by N4M | last post: by
4 posts views Thread by Leslaw Bieniasz | last post: by
1 post views Thread by masood.iqbal | last post: by
3 posts views Thread by PengYu.UT | last post: by
6 posts views Thread by Bit byte | last post: by
11 posts views Thread by toton | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.