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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:21:18+00:00 2026-06-08T23:21:18+00:00

I am confused with C++ vector and ask for help. I declare a class

  • 0

I am confused with C++ vector and ask for help.
I declare a class CBoundaryPoint:

class CBoundaryPoint:
{
public:
    double m_param;
    int m_index;    
}

And then I define a vector:

vector<CBoundaryPoint> vBoundPoints;
CBoundaryPoint bp;
double param;
// other codes
bp.m_param = param;
vBoundPoints.push_back( bp );

It surprises me that for every element in vBoundPoints, the value of m_param is totally different from the given value param. I just don’t know why.

For Example:

param = 0.3356;
bp.m_param = param; // so bp.param equals to 0.3356;
vBoundPoints.push_back( bp ); // while (*(vBoundPoints.end()-1)).m_param = -6.22774385622041925e+066;  same case to other elements

So what happened and why? I’m using VS2010.

  • 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-06-08T23:21:21+00:00Added an answer on June 8, 2026 at 11:21 pm

    You probably get garbage when you resize the vector or create a vector of a certain size using the size_type constructor. You get default-constructed objects in your vector, and these contain primmitive types. Since you have no user defined default constructor, the values are essentially random, or “garbage”.

    You can fix this by adding a default constructor to your class:

    class CBoundaryPoint:
    {
    public:
        CBoundaryPoint : m_param(), m_index() {} // initializes members to 0. and 0
        double m_param;
        int m_index;    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a class: someclass header code: class SomeClass{ SomeClass(); vector<int> somePointerVector; public: SomeClass(vector<int>
public class program1{ public static void main(String args[]){ java.util.Vector vc=new java.util.Vector(); vc.add(111); vc.add(222); functioncall(vc);
I've always been a bit confused about how STL containers (vector, list, map...) store
This looks simple but I am confused: The way I create a vector of
I am confused about how to use destructors when I have a std::vector of
I have a custom Vector class that contains an x, y, and z. These
If I have the following: vector<int> v(4,0); vector<int>* p = &v; int element =
I am totally confused with regards to deleting things in C++. If I declare
I am trying to get a vector to store objects of class 'Complex'. This
I'm learning Clojure and am confused by the following: (vector "1") ;; returns ["1"]

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.