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

  • Home
  • SEARCH
  • 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 8479021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:54:35+00:00 2026-06-10T18:54:35+00:00

I have a class template, let’s call it A , which has a member

  • 0

I have a class template, let’s call it A, which has a member function abc():

template <typename T>
class A{
public:
    T value;
    void abc();
};

I can implement the member function abc() outside the class declaration, using the following syntax:

template <typename T>
void A<T>::abc()
{
    value++;
}

What I want to do is to create a template specialization for this class, let’s say int.

template <>
class A<int>{
public:
    int value;
    void abc();
};

The question is: what is the correct syntax to implement abc() for the specialized class?

I tried using the following syntax:

template <>
void A<int>::abc()
{
   value += 2;
}

However this doesn’t compile.

  • 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-10T18:54:37+00:00Added an answer on June 10, 2026 at 6:54 pm
    void A<int>::abc()
    {
       value += 2;
    }
    

    since A<int> is explicit specialisation of A<T>.

    http://liveworkspace.org/code/982c66b2cbfdb56305180914266831d1

    n3337 14.7.3/5

    Members of an explicitly specialized class template are
    defined in the same manner as members of normal classes, and not using the template<> syntax
    .

    [ Example:

    template<class T> struct A {
    struct B { };
    template<class U> struct C { };
    };
    template<> struct A<int> {
    void f(int);
    };
    void h() {
    A<int> a;
    a.f(16);
    }
    // A<int>::f must be defined somewhere
    // template<> not used for a member of an
    // explicitly specialized class template
    void A<int>::f(int) { /∗ ... ∗/ }
    

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

Sidebar

Related Questions

Let's say we have a template class Area , which has a member variable
Let's assume we have a template function foo: template<class T> void foo(T arg) {
I have a class template <typename Iterator, typename Value> class Foo { public: Foo(const
Let's say I have this : class A { virtual int Method2(){/*...*/} }; template<typename
Let's say we have a class, MyParent: class MyParent { public: template<namespace T> MyParent()
let's say I have the following code in A.cpp file: template <typename T> class
I have a template class: template<class T> class A{ T a, b; public: A(A<T>
I have the following class: template <typename T> class matrix { private: int _n;
I have a template class method like that: template<class T> static tmpClass<T>* MakeInstance(T value)
I have a templated class template <typename Data> class C { ..... } In

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.