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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:01:43+00:00 2026-06-11T04:01:43+00:00

Where do I have to specify default template parameters of classes member functions (assuming

  • 0

Where do I have to specify default template parameters of classes member functions (assuming that the declaration is (of course) in the “class body”, and the function definition is outside the class body) for each case in C++2011 :

  • “normal” functions
  • static functions
  • friend functions

In the definition, in the declaration or both ?

  • 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-11T04:01:44+00:00Added an answer on June 11, 2026 at 4:01 am

    Well,
    From my experiences creating template classes and methods, you specify a template function as such:

    template<typename T>
    T MyFunc(T &aArg1, T &aArg2)
    {
        //...Definition Goes Here
    }
    

    The typename T is the template argument type for the template function and you need to pass that data type consistently to each argument labeled as “T”. This means that aArg2 has to be whatever data type aArg1 is. Now, when you call this function, you call it like so:
    MyFunc</*datatype*/int>(iArg1, iArg2); the two arguments have to be data type “int” or you’ll get a warning or an error.

    Now, this also applies to class methods (I think that is what you meant by “classes member functions”) which are the functions supplied by the class (i.e. MyClass::MyFunc()) so when you declare a class method that is a template method, you do it in the same manner. Here is an example class:

    class MyClass
    {
       MyClass();
       ~MyClass();
    
       template<typename T> 
       static T MyStaticFunc(T aArg) { return aArg; }
    
    
       template<typename T> 
       T MyFunc(T aArg) { return aArg; }
    }
    

    As you can see, not to difficult. Now, static functions are the same way you just have to be sure t define then in the same module that the class is built in, otherwise, you’ll get an error.

    Unfortunately, I never really use “friend” methods, so I don’t know how to tackle that. I would suspect you would do it in the same way as the other two. I hoped that whole essay of an answer helped.

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

Sidebar

Related Questions

I see that some C libraries have ability to specify custom memory allocators (
I ran gem sources -c so that I have to deliberately specify where I
I have a method that I specify to be of a certain type. E.g.
Is it possible to forward declare a class that uses default arguments without specifying
I have written a list-like template class sll (Single Linked List). Now, I am
I noticed that with the optional parameters in C# 4 if you specify an
I have an editor template for a custom object. Inside that editor template I
I have an ImageButton with a background image that has some transparency. By default,
If I declare a base class (or interface class) and specify a default value
I have a constructor prototype that looks like: template <typename type_position> window( const int

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.