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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:46:05+00:00 2026-06-15T23:46:05+00:00

I came across an interesting point that I wasn’t able to explain or find

  • 0

I came across an interesting point that I wasn’t able to explain or find an explanation for. Consider the following template definition (compiled with mingw g++ 4.6.2):

template <typename T, typename S>
class Foo
{
public:
    void f(){}
    void g(){}
};

Should we want to, we can fully specialize any single member function:

template <>
void Foo<char,int>::f() {}

But partial specialization fails with an "invalid use of incomplete type ‘class Foo<…>’" error:

template <typename T, typename S>
void Foo<T,S*>::f()
{
}

template <typename T>
void Foo<T,int>::f()
{
}

And I can’t figure out why. Is it a conscious design decision made to avoid some problem I can’t foresee? Is it an oversight?

  • 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-15T23:46:05+00:00Added an answer on June 15, 2026 at 11:46 pm

    The notion of partial specialization only exists for class templates (described by §14.5.5) and member templates (i.e. members of a template class that are themselves template functions, described by §14.5.5.3/2). It does not exist for ordinary members of class templates, nor does it exist for function templates – simply because it is not described by the Standard.

    Now, you might argue that by giving the definition of a partial specialization of a member function, such as

    template <typename T>
    void Foo<T,int>::f()
    { }
    

    you implicitly define a partial specialization of the class template: Foo<T,int>. That, however, is explicitly ruled out by the Standard:

    (§14.5.5/2) Each class template partial specialization is a distinct template and definitions shall be provided for the members of a template partial specialization (14.5.5.3).

    (§14.5.5.3/1) […] The members of the class template partial specialization are unrelated to the members of the primary template. Class template partial specialization members that are used in a way that requires a definition shall be defined; the definitions of members of the primary template are never used as definitions for members of a class template partial specialization. […]

    The latter implies that it is impossible to implicitly define a partial specialization by simply giving the definition of one of its members: The very existence of that member would not follow from the definition of the primary template, hence defining it is equivalent to defining a member function that wasn’t declared, and that isn’t allowed (even with non-template classes).

    On the other hand, the notion of explicit specialization (or full specialization, as you call it) exists for member functions of class templates. It is explicitly described by the Standard:

    (§14.7.3/1) An explicit specialization of any of the following:
    […]
    — member function of a class template
    […]
    can be declared by a declaration introduced by template<>; […]

    §14.7.3/14 describes the details:

    (§14.7.3/14) A member or a member template of a class template may be explicitly specialized for a given implicit instantiation of the class template, even if the member or member template is defined in the class template definition. […]

    Hence, for explicit specializations of members, the instantiation of the rest of the class template works implicitly – it is derived from the primary template definition, or any partial specializations if defined.

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

Sidebar

Related Questions

So, I came across an interesting method signature that I don't quite understand, it
I came across an interesting question today where I have two methods that, at
I was reading Django Book and came across interesting statement. Notice that Django doesn’t
I recently came across an interesting line of code that waits until a particular
I came across some interesting C# syntax that I'm not familiar with in the
I came across an interesting package that does fast navigation by character, but I
I came across an interesting expression in Ruby: a ||= new It means that
I came across an odd bug in my code that revealed an interesting behavior
An interesting issue came up recently. We came across some code that is using
I came across an interesting algorithm question in an interview. I gave my answer

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.