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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:27:59+00:00 2026-05-26T07:27:59+00:00

I am attempting to template a vector. In my main I have the following:

  • 0

I am attempting to template a vector. In my main I have the following:

std::vector<Word> concordance = push_vector(data);

Where Word is a struct containing a std::string and an int, and data is a std::string. In my header file I have:

 template <typename T>
 std::vector<T> push_vector(std::string&);

However when I compile I get the following error:

main.cpp: In function ‘int main(int, char**)’:
main.cpp:27:53: error: no matching function for call to ‘push_vector(std::string&)’
main.cpp:27:53: note: candidate is:
templates.h:13:20: note: template<class T> std::vector<T> push_vector(std::string&)

I know I am missing something when I am implementing my template function, but I am not sure what. Thank you for your time in advance.

  • 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-26T07:28:00+00:00Added an answer on May 26, 2026 at 7:28 am

    If I understand what you actually want to do perhaps something more like this:

    template <typename T>
    void push_vector(const std::string& str, std::vector<T>& vec)
    {
       // convert str to T if possible
       // throw on failure maybe?
       // assign vec with converted data
    }
    

    Then call it like so:

    std::string data("Hello");
    std::vector<Word> concordance;
    push_vector(data, concordance);
    

    Otherwise you would have to explicitly give the function it’s template argument as it can’t deduce from the rvalue you are assigning the return value into what the type should be. Not too mention passing an out paramater by reference like this saves you some performance.

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

Sidebar

Related Questions

I have a std::vector< tr1::shared_ptr<mapObject> > that I'm trying build from data contained in
I would like to create a template function that returns either int or std::vector<int>
I am attempting to compile the following template based code in VC++ 2005. #include
I'm attempting to have a derived class (normal template) that has a variable of
The following code used to function without attempting to render a new template with
I am attempting to register the following function from Irrlicht, dimension2df: template <class U>
I am attempting to create a template that will utilize data from an Access
The following used to work in WP 7.0: I'm attempting to re-template the root
I have been attempting to perform multiple (different) string replacement with recursion and I
I am attempting to create a vector iterator within a template class I am

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.