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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:09:01+00:00 2026-05-25T14:09:01+00:00

I have a class: C.h class C { private: template<int i> void Func(); //

  • 0

I have a class:

C.h

class C {
private:
  template<int i>
  void Func();

  // a lot of other functions
};

C.cpp

// a lot of other functions

template<int i>
void C::Func() {
 // the implementation
}

// a lot of other functions

I know, that it’s not the best idea to move template implementation in cpp file (because it won’t be seen from other cpp’s, which could include the header with the template declaration).

But what about private functions? Could anyone tell me if there are cons of implementing of private template functions in a .cpp file?

  • 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-25T14:09:01+00:00Added an answer on May 25, 2026 at 2:09 pm

    When a function template is used in a way that triggers its instantiation, a compiler(at some point) needs to see that template’s definition. And that is the reason, templates are usually implemented inside a header file using inline finctions.

    So as long as the above rules gets followed it is still okay to have interface and implementation separated in header and source files.


    Reference:
    C++03 standard, § 14.7.2.4:

    The definition of a non-exported function template, a non-exported member function template, or a non-exported member function or static data member of a class template shall be present in every translation unit in which it is explicitly instantiated.

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

Sidebar

Related Questions

I have a template class like below. template<int S> class A { private: char
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
If I have a class as follows class Example_Class { private: int x; int
I have a class like this public class foo { private void getThread() {
I have a class class fobj{ public: fobj(int i):id(i) {} void operator()() { std::cout<<Prints<<std::endl;
I have a template class ArrayTemp that creates an array of pointers to type
I have a class something like that: template <class T> class bag { public:
I have a template based class [Allotter.h & Allotter.cpp]: template <typename allotType> class Allotter
I have a c++ templated class: template<class T> class A { void test (T
I have a sample code below. #include<iostream> template<typename T> class XYZ { private: T

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.