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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:50:50+00:00 2026-05-16T18:50:50+00:00

When can you omit the C++ template argument list? For example in Visual Studio

  • 0

When can you omit the C++ template argument list? For example in Visual Studio 2010 this piece of code compiles fine:

template<class T>
Vec2<T> Vec2<T>::operator+ (const Vec2 &v) const
{
    return Vec2(x + v.x, y + v.y);
}

If you inline the code, it actually compiles without any argument list. But is this really the same as the following version?

template<class T>
Vec2<T> Vec2<T>::operator+ (const Vec2<T> &v) const
{
    return Vec2<T>(x + v.x, y + v.y);
}
  • 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-16T18:50:51+00:00Added an answer on May 16, 2026 at 6:50 pm

    Inside a class you can omit the argument on the class type:

    template<typename K>
    struct A {
       A<K> foo1; // legal
       A foo2; // also legal and identical to A<K> foo
       A bar(A x) {...} // same as A<K> bar(A<K> x) {...}
    };
    

    Outside of a class scope you need the template arguments:

    // legal
    template<typename K>
    A<K> foo(A<K> x) { return A<K>(); }
    
    // illegal!
    template<typename K>
    A foo(A x) { return A(); }
    

    If you declare a member function outside the class, you need the template list for the return type and for the class:

    // legal
    template<typename K>
    A<K> A<K>::bar(A<K> x) { return A<K>(x); }
    
    // legal
    template<typename K>
    A<K> A<K>::bar(A x) { return A(x); }
    
    // illegal!
    template<typename K>
    A A::bar(A<K> x) { return A<K>(x); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to refactor this code so that it can omit unnecessary
How can I omit Zeros in my data? For example using the MIN function?
I have my templated container class that looks like this: template< class KeyType, class
I want to use using statement purely for scope management. Can I omit holding
Can someone thoroughly explain the last line of the following code: def myMethod(self): #
How can I insert the youtubeId parameter in the following code : <?xml version=1.0
I can't figure out how to do this very simple thing: My page contains
In the book 'C++ In A Nutshell', there is the following example code std::vector<int>
I am having trouble using the XSLT 1.0 function library (since .NET/Visual Studio doesn't
<xsl:output method=text omit-xml-declaration=yes /> <xsl:template match=/Update/Object/Insert> Insert into <xsl:value-of select=@Table />( <xsl:for-each select=Field> <xsl:value-of

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.