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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:32:06+00:00 2026-05-16T04:32:06+00:00

I was expecting the second assert in the following to pass. I’m asking for

  • 0

I was expecting the second assert in the following to pass. I’m asking for your help.

Edit: It didn’t work when I had poss everywhere instead of poss_a in some places.

#include <vector>
#include <cassert>

class Sampler
{
public:
 std::vector<int*> poss;
 std::vector<int*>::const_iterator poss_it;
 Sampler(std::vector<int*> poss_a) : poss(poss_a), poss_it(poss.begin())
 {
  assert( (poss[0]) == (*poss_it) ); //passes
 }
};

int main()
{
 int someInt;
 std::vector<int*> poss_a(1, &someInt);
 Sampler sampler(poss_a);
 assert( ((sampler.poss)[0]) == (*(sampler.poss_it)) ); //passes now

 return 0;
}
  • 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-16T04:32:07+00:00Added an answer on May 16, 2026 at 4:32 am

    The poss_it(poss.begin()) line in your initializer list is pulling an iterator from the poss that is the input to the constructor, not the one that is a field of the class.

    This is a scope issue. When you’re in the constructor, it’s fine, because your iterator is a pointer to the input to the function. When you leave the constructor however, it’s pointing to the same spot in memory but now you have no idea what’s at that location.

    You should change the name of the input variable in the constructor. You want one that does this:

    Sampler(std::vector<int*> input) : poss(input), poss_it(poss.begin())
    

    Whereas what your current one is doing is this:

    Sampler(std::vector<int*> input) : poss(input), poss_it(input.begin())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was expecting the following code to throw an exception when I goto write
I was expecting the below scenario common, but couldn't find much help online. I
I have the following JQUERY code that I'm expecting to return 3 json results
unixtimestamp values are not liner? In the following example, I was expecting the 599
Here is example of code I'm expecting to print message each second. set_time_limit(0); foreach($array
I am expecting to implement a work flow like this. Browse facebook Canvas Page
I was expecting a Linux API similar to the Windows API. All I see
I am not expecting a definite yes or no. Any knowledge you might have
I am expecting users to upload a CSV file of max size 1MB to
By design I'm expecting a DuplicateKeyExeception from time to time. Is it possible to

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.