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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:27:08+00:00 2026-05-23T14:27:08+00:00

Is CRTP capable enough to outsmart virtual functionality completely ? The only disadvantage I

  • 0

Is CRTP capable enough to outsmart virtual functionality completely ?

The only disadvantage I see with CRTP is notable amount of code generated for every recurring pattern. For smaller designs, (where 2-3 classes are derived from a base), is CRTP a better idea ?

  • 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-23T14:27:08+00:00Added an answer on May 23, 2026 at 2:27 pm

    CRTP does not provide runtime polymorphism. If you need runtime polymorphism, you need virtual methods. Worse, since the base class is templated, you can’t even really use the subclass objects as if they were of the same type as the base class since you can’t cast them to that base class — it doesn’t exist; it’s just a template.

    I think a more useful way of thinking about polymorphism-replacing CRTP is not as a replacement for virtual inheritance, but rather as a form of mixins. You aren’t making subclasses in the usual sense; instead, you’re adding pre-made functionality to your class.

    Mixin example: an example of a mixin would be something like depends-on. Such a mixin might contain a list of pointers to other items of the same type on which this item depends; it’d add a method register_dependency that adds an object it depends on and visit_dependents which visits all its dependencies in (reverse?) topological order. Another example could be something that adds a compute_area method to anything which itself contains width and height methods. Or whatever…

    If you think of it as a replacement for a type hierarchy, you’re just making harder to comprehend, harder to debug code that doesn’t quite work the way it should. Unless you really need the performance gain (if any — not guaranteed), this sounds like a bad idea. If you’re doing it to quickly glue on some extra bits but without the conceptual weight of inheritance, I’d say you’re fine — “Real” inheritance isn’t necessary that frequently anyhow.

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

Sidebar

Related Questions

Here is some CRTP based template code that I used to try and resolve
I have a use of the CRTP that doesn't compile with g++ 4.2.1, perhaps
I'm using the curiously recurring template pattern (CRTP) in my C# project, but I'm
Without referring to a book, can anyone please provide a good explanation for CRTP
OK here we go. I'm trying to use the CRTP template in order to
I have a performance critical piece of code for which I am considering using
Given the following CRTP type in C#: public abstract class DataProviderBase<TProvider> where TProvider :
I've just learned about the CRTP Pattern and am looking for the original work.
I try to use the Curiously Recurring Template Pattern (CRTP) and provide additional type
I just read the wiki article about CRTP , and I'm a little confused

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.