DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Asa Guest

    overloading a virtual function


    Hi,
    is it possible to overload a virtual function like the following:

    I have an abstract base class, let's call it BaseProtocol. BaseProtocol has
    a virtual function, called receive(type_a ...)

    I have two classes that inherit from BaseProtocol, we can call them Protocol1
    and Protocol2.

    What I want is the following:

    Protocol1 should implement the virtual function with type_a, receive(type_a)


    and

    Protocol2 should implement the virtual function with a type_b,
    receive(type_b)

    Is this possible to do by overloading the virtual receive() in the base class???
    It would be great if someone knows anything about this.

    Thanx/Asa

  2. #2
    Danny Kalev Guest

    Re: overloading a virtual function

    Asa,
    In general, you can override a virtual function only if the signatures
    of the base and derived versions match. In your example, the signatures
    don't match so what you're actually getting is a function that hides the
    base class's virtual. Why don't you define two virtuals in the base
    class? Alternatively, you can hide the actual parameter's type in a
    uniform class or struct (or even void*, not my favorite way of using C++
    but sometimes it's inevitable).

    Danny

    Asa wrote:
    >
    > Hi,
    > is it possible to overload a virtual function like the following:
    >
    > I have an abstract base class, let's call it BaseProtocol. BaseProtocol has
    > a virtual function, called receive(type_a ...)
    >
    > I have two classes that inherit from BaseProtocol, we can call them Protocol1
    > and Protocol2.
    >
    > What I want is the following:
    >
    > Protocol1 should implement the virtual function with type_a, receive(type_a)
    >
    > and
    >
    > Protocol2 should implement the virtual function with a type_b,
    > receive(type_b)
    >
    > Is this possible to do by overloading the virtual receive() in the base class???
    > It would be great if someone knows anything about this.
    >
    > Thanx/Asa


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links