Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7439511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:43:00+00:00 2026-05-29T10:43:00+00:00

Whilst digging through the STL sources (DinkumWare, SGI, STLport, etc..) and trying to make

  • 0

Whilst digging through the STL sources (DinkumWare, SGI, STLport, etc..) and trying to make sense of their implementation choices (it’s going well), I came across something I feel is a bit odd or rather ive never run into before.

Generally when one wishes to overload a member function in a derived class, you would prepend the base class member function signature with the virtual keyword, however at various points in the STL source this is not the case.

Here is a cut-down version of what I’m seeing in the STL implementations:

template <typename T> class A {
public:
    void func( ) { std::cout << "inside A func( )" << std::endl; }
};

template <typename T> class B : public A<T> {
public: 
    void func( ) { std::cout << "inside B func( )" << std::endl; }
};

The compiler seems fine with this pseudo-polymorphism, where as I was expecting an error something along the lines of:

error C2535: 'void B<T>::func(void)': member function already defined or declared

Would someone be kind enough to explain what is going on here?

PS: This also seems to work without the classes being templates too.

‘Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:43:01+00:00Added an answer on May 29, 2026 at 10:43 am

    Without the virtual keyword – when redefining a function, you are hiding the super’s function.

    In your case, by redifining func(), you tell the compiler there is a new function for B, which is different from A‘s.

    Though, because it is not declared virtual, you will see this affect only if you invoke func() from a variable of type B. A variable of type A which holds a B, will invoke A‘s func().

    A *a = new B;
    a->func()
    

    will invoke the first [A‘s] method.

    To invoke B‘s method, you need the type to be B:

    B *b = new B;
    b->func()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whilst asynchronous IO (non-blocking descriptors with select/poll/epoll/kqueue etc) is not the most documented thing
Whilst reading through the book The well grounded Rubyist, I came across some strange
Whilst writing working my way through a list of scripts I need to write
Whilst going through the ADO.Net Entity Data Model wizard, I select 3 tables from
Whilst 'investigating' finalisation (read: trying stupid things) I stumbled across some unexpected behaviour (to
Whilst trying to convert the number from the value of a numericupdown to an
Whilst trawling through some old code I came across something similar to the following:
Whilst looking for a C++ implementation of Excel's NORMDIST (cumulative) function I found this
Whilst reading through the DirectWrite source code I came across the following struct: ///
I've run into a slight issue whilst trying to embed the Justin.tv player into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.