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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:09:23+00:00 2026-06-11T01:09:23+00:00

Possible Duplicate: “invalid use of incomplete type” error with partial template specialization Why is

  • 0

Possible Duplicate:
“invalid use of incomplete type” error with partial template specialization

Why is it that I can do this:

template <typename T>
struct A
{
    void foo(int);
};

template <>
void A<int>::foo(int)
{
}

but not this:

template <typename> struct C {};

template <typename T>
struct A
{
    void foo(int);
};

template <typename T>
void A<C<T> >::foo(int)
{
}

For the second case, GCC gives the following error:

test.cpp:10:23: error: invalid use of incomplete type 'struct A<C<T> >'
test.cpp:4:8: error: declaration of 'struct A<C<T> >'

EDIT:

When explaining why the second example is not allowed, please also consider that making the member function also a template has no effect on which example works and which does not. That is, this still works:

template <typename T>
struct A
{
    template <typename U>
    void foo(U);
};

template <>
template <typename U>
void A<int>::foo(U)
{
}

but this does not:

template <typename> struct C {};

template <typename T>
struct A
{
    template <typename U>
    void foo(U);
};

template <typename T>
template <typename U>
void A<C<T> >::foo(U)
{
}

So the reason cannot be that function templates can only be fully specialized, because the third example is not a full specialization (the template parameter U is still there), and yet it works.

  • 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-11T01:09:25+00:00Added an answer on June 11, 2026 at 1:09 am

    Function templates can only be specialised completely, not partially.

    You’re using the fact that member functions of class templates are themselves function templates, so this rule still applies.


    As for your edit: The following things can be explicitly (i.e. completely) specialized, from 14.7.3/1:

    An explicit specialization of any of the following:

    — function template

    — class template

    — member function of a class template

    — static data member of a class template

    — member class of a class template

    — member enumeration of a class template

    — member class template of a class or class template

    — member function template of a class or class template

    can be declared by a declaration introduced by template<>;

    I’ve emphasized the two statements that apply to your case. Absent any other explicit provisions, those entities can not be specialized partially.

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

Sidebar

Related Questions

Possible Duplicate: “Invalid use of 'this' in non-member function” in objective-c context? If I
Possible Duplicate: g++ “is not a type” error The following does not compile: 1
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I'm finding that dictionary
Possible Duplicate: Weird “406 not acceptable” error following code generate a 406 Not Acceptable
Possible Duplicate: PHP: “Notice: Undefined variable” and “Notice: Undefined index” This code shows warnings
Possible Duplicate: “Undefined reference to” template class constructor I've just started using templates, and
Possible Duplicate: “main” function in Lua? In Python, you can check if a script
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument Edit: This has nothing
Possible Duplicate: “Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given” error while
Possible Duplicate: setTimeout and “this” in JavaScript I am trying to put a timeout

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.