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

The Archive Base Latest Questions

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

So, I have a vector that is either full of integers. Lets call this

  • 0

So, I have a vector that is either full of integers. Lets call this vector Vect. I have my code in main.cpp and VectorList.h, and cannot change that fact. In VectorList.h one of my functions is:

void insertAtFront( const int & );

Now where I’m encountering trouble, I know I can add the integer to the start of the vector using std::vector.insert() function. But, insertAtFront does not have access to the vector itself, however, this is the only data member in VectorList.h:

vector< int > *vList

So, my question is how can I add a value to the beginning of a vector Vect using only this pointer *vList?

My first idea was something like this:

&vList.insert(&vList.begin(), 1, &value)    // with value being the input integer

but that doesn’t work :/ any suggestions?

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

    If you have a pointer to a vector, then you would need to use the -> operator. Using the & operator in this case will give you the address of the return value of vList.begin(). That won’t work too well, considering you can’t use the . operator on a pointer to begin with. Instead, you need to dereference the pointer. Try:

    vList->insert(vList->begin(), value);

    Edit: I’m not sure why you would need the middle argument in this case. You should be fine omitting it. I have done so in the line of code I wrote here.

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

Sidebar

Related Questions

I have a Vector that holds a number of objects. My code uses a
I have a vector in R that looks like this: dat <- c(TRUE, TRUE,
I have a large nested vector that look like this: import Data.Vector let x
I have this bit of code: cerr << client->inventory.getMisc().front()->getName() << endl; vector<itemPtr>::iterator it; it
For simplicity lets assume that I have a vector of N matrices each of
I have a class Vector that represents a point in 3-dimensional space. This vector
I have a vector that is constantly being updated (about 5-20 times a second)
I have a vector that I want to use to create a heap. I'm
I have a vector that holds pointers to abstract type Rock : vector<Rock*> rocks;
I have an std::vector that holds all the objects and is passed to them

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.