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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:41:13+00:00 2026-05-29T20:41:13+00:00

To define a specialization that is used for every Vector of pointers and only

  • 0

To define a specialization that is used for every Vector of pointers and only for
Vectors of pointers, we need a partial specialization:

 template <class T> class  Vector <T *> : private Vector<void *> {
 public:
      typedef Vector<void*> Base;
      Vector(): Base() {}
      explicit Vector(int i) : Base(i ) {}
      T *& elem(int i ) { return static_cast <T *&> (Base::elem(i)); }
      T *& opeator[](int  i) { return static_cast <T *&>(Base::operator[](i )); }
      //...
 };

This definition has me in a tizzy. This is related to partial specialization but i don’t understand the syntax. private Vector<void *> definition part looks like a parent class to me.

  1. Why not specify Vector <void *> in template <class T> class Vector <void *>.
  2. It would be great if anybody can breakdown the definition part. (sorry if its too much to ask)
  • 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-29T20:41:15+00:00Added an answer on May 29, 2026 at 8:41 pm

    Forget about the inheritance, which has nothing to do with the problem at hand.

    Partial specialization means that you make a new template from an existing one which is more specialized, but still generic, by matching a more restrictive pattern. The general pattern of your example is like this:

    template <typename T> class Foo;      // primary template
    
    template <typename U> class Foo<U*>;  // partial specialization
    
    template <> class Foo<fool>;          // full specialization
    

    The first line is the primary template and matches everything that is not matched by a more specialized form. The third line defines an actual type (not a template!) Foo<fool> (for some given type fool). The middle line, on the other hand, is still a template, but it only matches a type of the form T = U *, i.e. a pointer:

     Foo<char> x;   // uses primary template with T = char
     Foo<fool> y;   // uses full specialization (nothing to be matched)
     Foo<int*> z;   // uses partial specialization, matching U = int
    

    About the Vector<void*>: It just turns out that the author chooses to define the partially-specialized Vector<U*> as deriving from a fixed class Vector<void*> (which would have to be fully specialized elsewhere).

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

Sidebar

Related Questions

I want to use partial specialization for a template class so that all children
I've got a class that has a read-only property defined that is actually a
I am studying C++ concepts - Template specialization and Partial template specialization. Have a
I define some Entities which works fine; for meta programming issues. I now need
I am trying to define a full specialization of std::basic_string< char, char_traits<char>, allocator<char> >
The usual definition for a specialization of a template function is something like this:
I would like to define inside a class a constant which value is the
I'm writing a templated C++ generic container class that can optionally maintain its contents
I have a metafunction: struct METAFUNCION { template<class T> struct apply { typedef T
Always considering that the following header, containing my templated class, is included in at

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.