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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:17:30+00:00 2026-06-07T23:17:30+00:00

Are methods of templated classes implied inline linkage (not talking about the inline optimization),

  • 0

Are methods of templated classes implied inline linkage (not talking about the inline optimization), or is it just templated methods which are?

// A.h

template<typename T>
class A
{
public:
    void func1();                       //  #1
    virtual void func2();               //  #2
    template<typename T2> void func3(); //  #3
};

template<typename T>
void A<T>::func1(){}    //  #1

template<typename T>
void A<T>::func2(){}    //  #2

template<typename T>
template<typename T2>
void A<T>::func3<T2>(){}    //  #3

Are all the above cases inline [linkage]? (Should I explicitly write inline for any of them)?

  • 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-07T23:17:31+00:00Added an answer on June 7, 2026 at 11:17 pm

    Template functions and member functions of template classes are implicitly inline1 if they are implicitly instantiated, but beware template specializations are not.

    template <typename T>
    struct test {
        void f();
    }
    template <typename T>
    void test<T>::f() {}           // inline
    
    template <>
    void test<int>::f() {}           // not inline
    

    By lack of a better quote:

    A non-exported template must be defined in every translation unit in which it is implicitly instantiated (14.7.1), unless the corresponding specialization is explicitly instantiated (14.7.2) in some translation unit; no diagnostic is required


    1 Only in the sense that multiple definitions are allowed for them, but not for optimization purpopses. You can manually mark them inline as a hint for the optimizer.

    See [basic.def.odr]/13.4 – the templates by themselves are excempt from ODR, not because they’re implicitly inline.

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

Sidebar

Related Questions

We have complex template classes that have some methods which will not work with
I have a templated class template <typename Data> class C { ..... } In
Given class Foo template <typename T> class Foo { public: ...other methods.. void bar()
I have many classes/methods like this: template<typename CharT, typename TraitsT = std::char_traits<CharT> > struct
I have a class Stack, using template, one of its methods is push, which
I have some basic questions about abstract classes/methods. I know the basic use of
I just learned about the Template Method pattern in this answer to a question
I frequently run into large, non-template classes in C++ where simple methods are defined
I have a templated class defined (in part) as template <class T> MyClass {
I have two classes as follows in a header file template<size_t N> class Parent{

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.