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

  • Home
  • SEARCH
  • 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 7621897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:18:44+00:00 2026-05-31T04:18:44+00:00

I want to define a constructor working with any constructor having begin, end, operator++.

  • 0

I want to define a constructor working with any constructor having begin, end, operator++.
In other words I want to get this behavior (commented, working code):

/*Polyn(std::vector<double> &a) : CalcDerivative(0) , CalcIntegral(0) {
    for(std::vector<double>::iterator i = a.begin();i < a.end();++i)
      params.push_back(*i);
    }*/

with other iterators. (for instance lists too).

template <typename T>
  Polyn(const T &a) : CalcDerivative(0) , CalcIntegral(0) {
  typename std::vector<T>::iterator iter;
  for(iter i = a.begin();i < a.end();++i) //LINEA 18!!
    params.push_back(*i);
  }

What I get is this compilation error:

polyn.h: In constructor ‘Polyn::Polyn(const T&)’:
polyn.h:18: error: expected ‘;’ before ‘i’

why? How to fix my code?

  • 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-31T04:18:46+00:00Added an answer on May 31, 2026 at 4:18 am

    In addition to Nawaz’s answer, if you want to support any container type supporting begin, end and a forward iterator, you may want to use:

    template <typename C>
    Polyn(const C &a) 
      : params(a.begin(), a.end()), CalcDerivative(0) , CalcIntegral(0) 
    {
    }
    

    This way it also works for std::lists and std::maps and whatever. Or, when having C++11 support, you should actually use the even more general std::begin(a) and std::end(a), so it will even work for plain arrays or anything else specializing std::begin and std::end.

    Another option, which is a bit more STL-like, would be to directly use iterators as arguments, but then you have to do the begin/end manually in the client code (when calling the constructor):

    template <typename InputIterator>
    Polyn(const InputIterator &b, const InputIterator &e) 
      : params(b, e), CalcDerivative(0) , CalcIntegral(0) 
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At first sorry my bad English. I want define routing for this url: For
Recently I have been working on a project where, among other things, we want
I want to get an onload event working on my config object. The following
I want a templated class with a templated conversion operator and a default constructor,
Assume I want to define two variables of class {Type}. The constructor takes 1
I want to define a following function: if(stmtToFinalize) { NSLog(@Finalizing statement stmtToFinalize); if (sqlite3_finalize(stmtToFinalize)
I want to define some properties on a class using the [Indexable()] attribute in
I want to define a class that supports __getitem__ , but does not allow
I want to define a constant in objective-c. Previously I had the following function:
I want to define a class method that has access to a local variable.

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.