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 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 an std::vector defined as: std::vector<glm::vec3> faces; And I want to use the
I have a struct that looks like this: typedef struct _my_struct { float first_vector[SOME_NUM][OTHER_NUM];
I have a class here that is defined like this: struct USERFPOINT { POINTFLOAT
Say I have: class Vector3 { float x, y, z; ... bunch of cuntions
in clojure i have vector [myfn1 myfn2 myfn3] how can i call functions named
I have a vector of beans that holds information I want to display in
I have a vector of pointers to a class. I need to call their
I have a vector containing the values 0, 1, 2 and 3. What I
I have a vector of booleans. I need to set its elements from n-th
I have a vector of pointers to objects. I'd like to remove objects from

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.