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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:00:58+00:00 2026-06-03T14:00:58+00:00

Alright, so we know functions in the STL like std::fill(boolContainer.begin(), boolContainer.end(), false); I’m working

  • 0

Alright, so we know functions in the STL like

std::fill(boolContainer.begin(), boolContainer.end(), false);

I’m working on a class with a method which also works on a container, and I’ve realized that I just as well might template it like in the example above The non-templated version is like this:

class SomeClass {
public:
    // ...
    int containerMethod(std::vector<int> &v);
    // ...  
private:
    // ...
};

And I’m aiming to change it into:

class SomeClass {
public:
    // ...
    template <class InputIterator>
    int containerMethod(const InputIterator &begin, const InputIterator &end);
    // ...  
private:
    // ...
};

However I’m having trouble working out the details for the implementation:

template <class Iter> int SomeClass::containerMethod
(const Iter &begin, const Iter&end) {
    // Here I need to instantiate an iterator for the container.
    Iter iter;
    for (iter = begin; iter != end; ++iter) {
        // This does not seem to work.
    }
    return 0;
}

So the question is how does one correctly instantiate a templated iterator, based on the templated parameters of a method? Note that I only need an input iterator.

  • 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-03T14:00:58+00:00Added an answer on June 3, 2026 at 2:00 pm

    Your test case is incomplete, so I have to consult my crystal ball.

    You have placed your template definition in a source code file, when it should have been in a header file.

    See: Why can templates only be implemented in the header file?

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

Sidebar

Related Questions

Alright, I know questions like this have probably been asked dozens of times, but
Alright, I know it can be done like so... $Array1 = array(Hello, , foo,
Alright, I wanna know why this code is working, I just realized that I
Alright I know this is more than likely a amateur question but I have
Alright, i dont know how to explain it well.. but i have a switch
Alright, so I know about the Settings.Properties.Default.* Stuff, but thats not what im trying
Alright, so as you probably know, static inheritance is impossible in C#. I understand
Alright, I know this question has been asked before, but mine has a different
Alright, I'm having a hard time explaining this, let me know if I should
Alright, this one's interesting. I have a solution, but I don't like it. The

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.