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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:44:24+00:00 2026-06-03T22:44:24+00:00

In this question the OP asked for a solution to template typedef which is

  • 0

In this question the OP asked for a solution to template typedef which is not possible in C++. The OP also presented a solution themselves but did not like it:

template<size_t N, size_t M>
class Matrix {
    // ....
};

// Problem - will not compile
typedef Matrix<N,1> Vector<N>;

// Solution
template <int N>
class Vector: public Matrix<N,1>
{ };

My question is, what advantage does the Helper::type solution give us over the OP’s solution (assuming these classes are never meant to be used by a base pointer or new‘d as such)? An empty class should carry no overhead in release (or does it?). The only disadvantage I can see is that in debug builds you will have to expand the base class when debugging.

EDIT: In addition to the selected answer, see @Dani’s answer who suggested that the inherited version would require constructors to be defined, which is an added inconvenience.

  • 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-06-03T22:44:27+00:00Added an answer on June 3, 2026 at 10:44 pm

    The point of typedef is to define a type alias. A subclass is not a type alias – it is a new type.

    For example, imagine some library function

    template<size_t N, size_t M>
    Matrix<N, M> * createMatrix();
    

    Now with helper type

    Vector<3>::type * var = createMatrix<3, 1>();
    

    is legal.
    With inheritance

    Vector<3> * var = createMatrix<3, 1>();
    

    is not.

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

Sidebar

Related Questions

This question was asked before but the solution is not applicable in my case.
I feel like this question has been asked many times, but the solution is
This question was previously asked and answered correctly, but there did not seem to
I have asked this question before with other adapters like SimpleAdapter but the solution
sorry I know this question was asked already but the solution doesn't work for
I know that this question asked a lot (i think) but i could not
I know this question was asked like a million times by now, but I
I asked this question earlier where a solution was presented. The solution is great
This question has been asked many times, but I tried every solution and none
I have asked this question sometime back. But havent got a solution yet, Here

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.