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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:27:42+00:00 2026-06-18T12:27:42+00:00

In VS2012 using c++11, why does this compile: template <typename T> class Vector2 {

  • 0

In VS2012 using c++11, why does this compile:

template <typename T>
class Vector2
{
public:
    Vector2();  //constructors

    T Dot(const Vector2<T>& U, const Vector2<T>& V);
};

template <typename T>
inline T Vector2<T>::Dot(const Vector2<T>& U, const Vector2<T>& V) //ISSUE
{ return (U.x * V.x + U.y * V.y); }

But this doesn’t:

template <typename T>
class Vector2
{
public:
    Vector2();  //constructors

    template<typename G>
    G Dot(const Vector2<G>& U, const Vector2<G>& V);
};

template <typename G>
inline G Vector2<G>::Dot(const Vector2<G>& U, const Vector2<G>& V) //ISSUE
{ return (U.x * V.x + U.y * V.y); }

The second causes an error: “unable to match function definition to an existing declaration”
I realize I don’t have to use G for the later template function definition, I’ve just used it to be consistent with the 2nd example declaration.
Are you not allowed to have a function in a template class that takes a different type than the class? I’m extremely interested in finding out what’s going on here and anything relevant about templates I can learn from this error.

  • 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-18T12:27:43+00:00Added an answer on June 18, 2026 at 12:27 pm

    You have two template types: T and G. One list (T) is for the class, and one (G) is for the member function. Therefore, you have to have two lists; one for the class, then one for the function (and make sure that the right types go in the right places, T after the class name and G in the parameters):

    template<typename T>
    template<typename G>
    inline G Vector2<T>::Dot(const Vector2<G>& U, const Vector2<G>& V)
    { return (U.x * V.x + U.y * V.y); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to shape results into FullList this using VS2012 & EF5: public class
Not sure this is a known issue. I’m using VS2012 RC (Ultimate), and Win8
We have a problem using a class template which itself uses function objects in
I have a class library that I created using the Class Library project template.
So using VS2010 (or SVCUTIL.EXE) to created a WCF class, it does not generate
I am using VS2012 and having some troubles publishing an mvc4 website. None of
I'm using VS2010 Ultimate. Having code: //file IntSet.h #include stdafx.h #pragma once /*Class representing
After I have installed VS2012 my Qt project does not compiler anymore (have VS2010
I'm using VS2012 and SQL Server Express 2008. I've boiled down my connection/query to
I'm using msbuild on the command line to build a VS2012 solution containing a

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.