Thread: Overloaded function where one signature is an inherited over ride

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    245

    Question Overloaded function where one signature is an inherited over ride

    Hi there,

    This is working but I'm a little nervous it might be pushing boundaries a bit. Have a look at the portion of the abstract class below:

    Code:
    class IMPORT_EXPORT D3DInterface
    {
    public:	
    
    ....stuff omitted
    
        virtual void    Update() = 0;
    
    ....class continues
    }
    So a pure virtual, which is making the class abstract. This class is used as the interface between the main app and the DLL. So anything inside the DLL inherits from this class and over rides the pure virtuals. It allows the main app to ultimately make API specific function calls without knowing anything about the API itself.

    Here's a shortened portion of the inheriting class:

    Code:
    class D3DRenderer : public D3DInterface
    {
    public:	
    
    ....stuff omitted
    
    void    Update()override;
    
    ....more stuff omitted
    
    void    Update(const GameTimer& gt);
    
    ....class continues
    So two function signatures, one an over ride, the other a typical class member function.

    Here's the two functions below:

    Code:
    void D3DRenderer::Update()
    {      
        Update(mTimer);
        return;
    }
    
    void D3DRenderer::Update(const GameTimer& gt)
    {
    
    ....function body
    
    }
    This allows the main app to call the over ridden Update() function which then delegates to the ordinary member function which takes a GameTimer object as an argument. I mean it works.... but I wonder if this will always work in the future, especially when just running it as an executable on other machines (if I ever get that far).

    I assume provided something is within a defined C++ standard then I don't have to worry. It just seems a little wild to me to allow a compiler to choose between two signatures when one of them is an over ride.

    I'm probably worrying about nothing, but I'd like a second opinion.

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,684
    override specifier (since C++11) - cppreference.com
    On the face of it, it seems override just ensures that your base class remains virtual.

    And Update(const GameTimer& gt) is just a normal member function of D3DRenderer subject to the normal function overloading resolution.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    245
    Great! Thanks very much Salem

  4. #4
    Registered User
    Join Date
    Sep 2024
    Posts
    10
    Quote Originally Posted by Salem View Post
    override specifier (since C++11) - cppreference.com
    On the face of it, it seems override just ensures that your base class remains virtual.

    And Update(const GameTimer& gt) is just a normal member function of D3DRenderer subject to the normal function overloading resolution.
    It seems to like the question was whether this function should be overloaded from the base class too, instead of just from the deriving class.

    Looking at the spec might help, but it doesn't look like there's something right away. It might take reading the whole spec to infer anything :-(

    ".... It just seems a little wild to me to allow a compiler to choose between two signatures when one of them is an over ride...."

    But, uhmm.... shouldn't be a problem because the resolution probably happens at compile time(?!?!), once again? :-)
    Last edited by ReDress; 3 Weeks Ago at 04:34 AM.

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    245

    Smile

    Quote Originally Posted by ReDress View Post
    But, uhmm.... shouldn't be a problem because the resolution probably happens at compile time(?!?!), once again? :-)
    Interesting thought thank you!

    Quote Originally Posted by ReDress View Post
    It seems to like the question was whether this function should be overloaded from the base class too, instead of just from the deriving class.
    Not really no to be honest, I never wanted the function overloaded in the base class. The base class is in the interface header that allows the main app and dll to communicate without the main app knowing anything about the rendering API (or any of the rendering specific functions and classes).

    If I were to overload the function in the base class I would have to add knowledge of one of the classes in the dll to the base class in the interface. I specifically do not want that for abstraction reasons.

    Thanks for your reply

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Signature of function accepting functor as argument?
    By StainedBlue in forum C++ Programming
    Replies: 10
    Last Post: 06-01-2010, 04:50 PM
  2. What exactly is a function signature?
    By Sharke in forum C++ Programming
    Replies: 21
    Last Post: 07-01-2009, 11:21 PM
  3. Changing an inherited function
    By Akkernight in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2009, 09:42 AM
  4. operator overloaded but not inherited
    By vaibhav in forum C++ Programming
    Replies: 5
    Last Post: 08-07-2006, 05:02 AM
  5. string::find_last_of function signature
    By WebSnozz in forum C++ Programming
    Replies: 6
    Last Post: 10-09-2002, 09:12 PM

Tags for this Thread