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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:14:02+00:00 2026-05-13T16:14:02+00:00

I have the following code snippet: vector<DEMData>* dems = new vector<DEMData>(); ConsumeXMLFile(dems); if(!udp_open(2500)) {

  • 0

I have the following code snippet:

vector<DEMData>* dems = new vector<DEMData>();
ConsumeXMLFile(dems);

if(!udp_open(2500))
{

}        

I want the ConsumeXMLFile method to populate the vector with DEMData objects built from reading an XML file. When ConsumeXMLFile returns, the dems vector is empty. I think I’m running into a pass by value problem.

  • 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-13T16:14:03+00:00Added an answer on May 13, 2026 at 4:14 pm

    Are you at any point reassigning the pointer that is passed into the function? In other words, does your function look anything like this:

    void ConsumeXMLFile(vector<DEMData>* dems) 
    {
       // ... some code ...
    
       dems = new vector<DEMData>();
    
       // ...more code...
    }
    

    This is a common mistake that I see beginning C++ programmers (and C programmers) make. What is going on here is that a pointer to the dems vector is being passed by value, which means that if you modify the pointed-to vector, that will affect the the vector possessed by the caller. However if you modify the pointer (which is passed by value) this will not affect the pointer possessed by the caller. After the re-assignment, the dems pointer in ConsumeXMLFile will point to a totally different vector than the dems pointer that the caller holds.

    One of the things that makes me suspect that you might be doing this is that this is C++ and there’s no clear reason why you would want to pass a pointer to the vector instead of a reference to the vector otherwise.

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

Sidebar

Related Questions

I have the following code snippet: using (SPSite site = new SPSite(this.ListAddress)) { using
i have the following code snippet. in which i just want to return PartyName
I have the following code snippet: std::vector< boost::shared_ptr<Foo> >::iterator it; it = returnsAnIterator(); //
I have following code snippet in c#. var list = new List<string> { a,
I have following code snippet query_area = new JTextArea(); query_scroll_pane = new JScrollPane(query_area); query_scroll_pane.setSize(1000,80);
I have the following code snippet: Dictionary<int, List<string>> likeListDict = new Dictionary<int, List<string>>(); List<string>
I have following code snippet in jquery.In which,I want to animate each element of
I have following code snippet: addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) {
I have following code snippet: self.xmlHttpReq = new XMLHttpRequest(); self.xmlHttpReq.onreadystatechange = function() { if(self.xmlHttpReq.readyState
I have following code snippet in c# List<int> list = new List<int>() { 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.