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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:52:28+00:00 2026-06-14T00:52:28+00:00

I have to create a function that takes in a vector of unknown item

  • 0

I have to create a function that takes in a vector of unknown item types.
Here is my code:

template <typename S>
void printVector(vector<S*> c){
   typename vector<S>::const_iterator A = c.begin();
   for (int A; A != c.end(); A++){
       cout<<c[A]<<" ";
   }
   cout<<endl;
}

In my main class here is my vector and function call:

vector<int> x;
int j=5;
for(int i=0;i<j;i++){
    x.push_back(num[i]);
}
printVector(x);

When I try to compile this code I get these errors:

exercise1_1.cpp: In function ‘int main()’:
exercise1_1.cpp:33:15: error: no matching function for call to ‘printVector(std::vector<int>&)’
exercise1_1.cpp:33:15: note: candidate is:
exercise1_1.cpp:13:7: note: template<class S> void printVector(std::vector<S*>)

  • 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-14T00:52:29+00:00Added an answer on June 14, 2026 at 12:52 am
    template <typename S>
    void  printVector(const std::vector<S>& c){
       typename std::vector<S>::const_iterator A = c.begin();
       for (; A != c.end(); A++){
           std::cout<<*A<<" ";
       }
       std::cout<<"\n";
    }
    

    Fixes:

    • Your function was declared to take a vector<S*> but you obviously want it to take vector<S>.
      • Your main function invoked print_vector with an argument of std::vector<int>. Since an int is not an S* for any type of S, the template did not apply.
    • You have redeclared A when you intended to use only the first declaration.
    • You conflated indexed access to the vector with access through the iterator.
      • If you have an int: c[i]
      • If you have an iterator: *it

    Less critical fixes:

    • Avoid using namespace std;
    • Never use std::endl when you mean "\n".
    • You should pass the parameter by const reference, not by value
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my problem, I need to create a javascript function that takes 2
I have the following function that takes a number like 5 and creates a
i have DataBase function that calculate distance by coordinates CREATE OR REPLACE FUNCTION distance(lat1
I currently have a function that will create X tasks of a function based
I have three classes that all have a static function called 'create'. I would
Does anyone have a working class or function to create the hashed email that
Why does my Instantiate function not create a 'Blank' instance of That? I have
I have this class that have a function to load other classes and create
I have a problem to create a preprocessor macro function, that concatenates two Strings
When you have a function with a string parameter, does that create another instance

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.