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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:13:47+00:00 2026-05-24T00:13:47+00:00

I have a vector of floats, defined by: std::vector<float>* MyVec; and I was filling

  • 0

I have a vector of floats, defined by:

std::vector<float>* MyVec;

and I was filling this inside a for loop later with:

MyVec->push_back(somevalue)

and I was getting a seg fault. In order to try and find out what was going on I commented out the push_back line and I still saw a seg fault, and when it seg faulted the size of MyVec was 490618047.

Is there perhaps something I have forgotten to do with this vector, and how is it getting filled by such a huge number without any entries being entered into the vector?

Thanks in advance.

  • 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-24T00:13:48+00:00Added an answer on May 24, 2026 at 12:13 am

    You’ve not allocated memory:

    std::vector<float>* MyVec = new std::vector<float>();
    

    Because MyVec is a pointer to std::vector<float>, you’ve to do the above, before using MyVec.

    Also, don’t forget to deallocate the memory, once you’re done with MyVec:

    delete MyVec;
    

    Apart from that, I think, you don’t need a pointer to begin with; if so, then you should do the following instead of declaring a pointer:

    std::vector<float> MyVec; //it is NOT a pointer.
    

    And use it as:

    MyVec.push_back(someFloatValue);
    
    • 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 I want to insert into a set . This
If I have a vector of pairs: std::vector<std::pair<int, int> > vec; Is there and
I have several std::vector , all of the same length. I want to sort
I have a std::vector containing a handful of numbers, which are not in any
I have a class here that is defined like this: struct USERFPOINT { POINTFLOAT
I have a vector class with a properly overloaded Vect*float operator and am trying
I have data coming over a socket that looks like this: (h)(int,char,float,int,char)(/h)(d)(2,a,1.32,45,d)(3,d,3.45,32,a)(/d) The datatype
I have a pointer array of a custom Vector typedef (just 3 floats). I'm
Suppose I have a class: public class Vector { public float X { get;
I have a vector-like class that contains an array of objects of type T

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.