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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:32:21+00:00 2026-05-22T22:32:21+00:00

I keep getting the following error when trying to write a template function: main.cpp|17|error:

  • 0

I keep getting the following error when trying to write a template function:

main.cpp|17|error: no matching function for call to ‘dotproduct(vector<float, 3u>&, vector<float, 3u>&)’|

I’ve searched on the error and found some other cases where a non-type template parameter could prove problematic if the parameter was a float or a double. Im using a non-type template parameter of size_t to determine the size of matrices and vectors.

I have the following classes:

matrix:

template<class element_t, size_t rows, size_t columns>
class matrix
{
private:
  element_t elements_[rows*columns];
  // ...
};

vector:

template<class element_t, size_t size>
class vector
  : public matrix<element_t, size, 1>
{
  //...
};

my function:

template<class vector_t>
typename vector_t::element_t dotproduct(const vector_t &vector0, const vector_t &vector1)
{
  typename vector_t::element_t result_(0);
  for(size_t index_ = 0; index_ < vector_t::rows * vector_t::colums; ++index_){
    result_ += vector0[index_] * vector1[index_];
  }

  return result_;
}

called from:

int main(int count, char *arguments[])
{
  typedef vector<float, 3> vec3;

  vec3 a = {1.0f, 2.0f, 3.0f}, b = {3.0f, 2.0f, 1.0f};

  std::cout << dotproduct(a, b) << std::endl;
  std::cin.get();
}

gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)

  • 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-22T22:32:21+00:00Added an answer on May 22, 2026 at 10:32 pm

    Names of template parameters may only be used inside the class (or function) template to which the template parameter list corresponds. It makes sense – standard makes no guarantees about template parameter names; they might be different even between two declarations!

    Consider:

    template <typename U, typename T>
    class A;
    
    template <typename T, typename U>
    class A
    { };
    
    int main()
    {
      A<int, char>::T some_variable; // which type parameter to use?
    }
    

    Because names of template parameters cannot be used, your function template is removed from overload candidates and because there are no other functions, overload resolution fails (basically what bluescarni said).

    Correct way to handle this is to typedef the template name. Once you do, the name becomes usable even from outside of class/function (well, unless it’s private).

    To correct your example, you need:

    template<class Element, size_t rows, size_t columns>
    class matrix
    {
    public:
      typedef Element element_t;
    private:
      element_t elements_[rows*columns];
      // ...
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use php's mail() function but keep getting an error. I've installed
I'm getting the following error when trying to build my app using Team Foundation
I'm trying to write to the windows registry at HKEY_CURRENT_USER\Software\appname however I keep getting
I'm running Python 2.5.4 on Windows and I keep getting an error when trying
I'm using Grails Mail plugin and trying to send email and keep getting: Error
I keep getting this writing to a closed file error while trying to compile
Hi I am trying to test a RESTful Application, but keep getting the following
I've tried many configurations, but I keep getting the following error upon opening eclipse:
I am trying to use the mvc-mini-profiler with MVC3 and keep getting the following
I have a web app built against asp.net 2.0, but keep getting the following

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.