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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:43:06+00:00 2026-06-04T15:43:06+00:00

A function template: template<class T> T max(T a, T b){return (a > b)? a:

  • 0

A function template:

template<class T> T 
max(T a, T b){return (a > b)? a: b;}

when use it:

max<int>(a, b); // Yeah, the "<int>" is optional most of the time.

but if you allow, we can write template this way:

T max<class T>(T a, T b){return (a > b)? a: b;} 
//I know the return type T is not in its scope, don't focus on that.

Thus we can maintain the same form of declaration and using just like normal function does. and even don’t need to introduce and type the keyword “template”. I think class template would be the same? So is there any other reason make the template become the form we know today?

i changed the form so that you don’t focus on the return type:

auto max<class T>(T a, T b) -> T {return (a > b)? a: b;}
//This is C++11 only and ugly i guess. 
//The type deduce happens at compile time 
//means that return type really didn't to be a problem.
  • 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-04T15:43:08+00:00Added an answer on June 4, 2026 at 3:43 pm

    The immediate answer that comes to my mind is:
    Just because someone who laid out the proposal for templates said so and no one on the standards committee felt that typing those extra 8 characters would be an overhead.

    On a different note:
    The syntax of templates is complicated and intimidating to begin with, making sure of presence of the keyword template makes it more intuitive to a reader of code that they are dealing with templates and not any of the other beasts provided by C++ or any implementation specific constructs(read compiler extensions).

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

Sidebar

Related Questions

When I define this function, template<class A> set<A> test(const set<A>& input) { return input;
I have following code: #include <iostream> using namespace std; template<class T> T max(T *data,int
can we declare a template function in a normal class with out a template
I have a template class with a variadic template member function that I am
Since the function template in the following code is a member of a class
What is the function of the following C++ template class? I'm after line by
Given a class with a member template function like this one: template <typename t>
Let's assume we have a template function foo: template<class T> void foo(T arg) {
Suppose I have a function which looks like this: template <class In, class In2>
I have the following templated function... template< class T > T *create_object( lua_State *L

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.