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 7026959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:11:08+00:00 2026-05-28T00:11:08+00:00

Here is some CRTP based template code that I used to try and resolve

  • 0

Here is some CRTP based template code that I used to try and resolve this question: Requiring overridden virtual functions to call base implementations. I would post code here, but the lines are long and easier to read on codepad.org (if needed I’ll post here). It’s ugly and it’s somewhat artificial, of course, although it does work. But what I didn’t realize at first, that while it compiles on both MSVC++ and GCC, some template types are not really defined. The part I’m questioning is several long inner if( typeid( Derived(N) ) != typeid( Derived(N-1)) (symbolic notation) in TBase::OnEvent function on top.

You cannot typdef these types, it will be a compilation error – there is simply not enough derived classes for type to be defined with such long ...::TDerived::... chain, so you’ll get, correctly, compilation error TDerived is not defined in TBase. Yet compiler eats them through typeid. When I checked in debugger MSVC++ compiler output (with full symbolic info), it seems that all those long ...::TDerived::... that should not really result in any class, in typeid resolved by compiler to simply the last TDerived04 in class chain. And RTTI is pulled for this last class in the class chain, independently of how many ...::TDerived::... I have.

Taking into account that both MSVC++ and GCC do that (although I only have access to GCC through codepad.org), my question is next: is it somehow defined behavior of typeid? Why then typedef of any of those long ...::TDerived::... does not resolve to TDerived04?

EDIT: I mean, I’m happy typedef does not resolve to TDerived04, that’d be disaster for anyone who uses typedef, but why such inconsistency between typeid and typedef?

EDIT: GCC accepts TDerived04::TDerived04::TDerived04::TDerived04 lD4; variable declaration. And the type is simply TDerived04 in the end. Is there a rule for collapsing scope resolution? Apparently, both MSVC++ and GCC seems to be doing the same in typeid, but MSVC++, unlike GCC, can’t handle other scenarios – it gives compile error, requiring arguments for constructor(s).

  • 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-28T00:11:09+00:00Added an answer on May 28, 2026 at 12:11 am

    I wouldn’t consider using typeid as anything else than a tool for debugging. C++ standard only guarantees its existance, but doesn’t really say what it should do. This renders this utitlity as nothing more than a way to print a human readable class names (please correct me if you know any other practical use).

    I would say there is too much “compiler defined” behaviour of typeid to make it useful for anything else than above.

    Approach presented in the solution also has a huge drawback. Besides being ugly and hard to maintain, the base class requires to know about all derived classes. This is quite a big design flaw.

    As for alternative solution it can be seen here (code also posted in original question).

    As for TDerived04::TDerived04::TDerived04::TDerived04 being valid is can be exaplained by that in TDerived04 class you can refer to this class/namespace using its name TDerived04. So TDerived04::TDerived04 is like pointing at class TDerived04 from TDerived04 (as @MSalters said it is called “class name injection”).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's some code (full program follows later in the question): template <typename T> T
Here is some code I could not get to format properly in markdown, this
I was recently reading a question here (some time this week), which I can't
Here some C++ code that is accessed from multiple threads in parallel. It has
I've got here some javascript code, that implements a signature pad. It works fine
Here's some Ruby code: puts %x{ pstree #{$$} } # never forks puts %x{
Here's some code I saw once. Can you see what's wrong with it? [updated]
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Im trying to get a form element value using closest. Here some example code.
I have some terribly written ASP.NET code that is just not working right (go

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.