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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:34:51+00:00 2026-06-04T14:34:51+00:00

For some reason this isn’t working for me. It gives me the vector iterator

  • 0

For some reason this isn’t working for me. It gives me the vector iterator out of range error.

directory_entry TDE("Path");
vector <directory_entry> Temp;
Temp.push_back(TDE);

User_Data->DPath.insert(User_Data->DPath.begin(), Temp.begin(), Temp.end());

But, this works,

vector <directory_entry> DPath;
directory_entry TDE("Path");
vector <directory_entry> Temp;
Temp.push_back(TDE);

DPath.insert(DPath.begin(), Temp.begin(), Temp.end());

I don’t think there is anything wrong with User_Data->DPath because I can push/pop and access elements in it. But for some reason I can’t seam to be able to use insert on it without getting out of range errors.

Does anyone know why this might be?

edit: A popup emerges, debug assertion failed. It gives me a line in the vector header file, 1111, and a message “Expression: vector iterator out of range”. If I make sure that there is at least one element in User_Data->DPath, and then start at .begin+1, I get “Expression: vector iterator+offset out of range” and it gives me line 157 of the vector header file.

edit: You are all probably right. The g_new0 function does the memory allocation http://developer.gnome.org/glib/2.32/glib-Memory-Allocation.html#g-new0

struct_type : the type of the elements to allocate. n_structs : the
number of elements to allocate. Returns : a pointer to the allocated
memory, cast to a pointer to struct_type.

typedef struct {
    vector <directory_entry> DPath;
}State;

static gboolian select_dir (ClutterActor *actor, ClutterEvent *event, g_pointer data){
    State *User_Data = (State*)data;

    directory_entry Temp(Path);
    User_Data->DPath.push_back(Temp);

    ...
    return TRUE;
}


int main( argc, char*argv[]){
State *data = g_new0 (State, 1); 

...  

 g_signal_connect(Cluter_Actor, "button-event", G_CALLBACK(select_dir), data)

 ...

 clutter_main();
 g_free(data);
 return 0;
 }
  • 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-04T14:34:53+00:00Added an answer on June 4, 2026 at 2:34 pm

    g_new0 is not a drop-in replacement for new

    new does two things: allocates memory for an object, and calls the object’s constructor. g_new0 only does the first, allocating memory. You need to call the object’s constructor explicitly if you want to use g_new0. This is done using “placement new”:

    State *data = g_new0 (State, 1); 
    new (data) State;  // placement new - calls the constructor
    

    The reason calling State‘s constructor is important is that it in turn calls the constructor of the vector<directory_entry> member of State, and this is what initializes the vector. Without initializing the vector properly, you cannot use it.

    Note that since you are calling the constructor explicitly, you will also need to call the destructor explicitly before freeing the memory:

    data->~State();  // call destructor
    g_free(data);    // free the memory
    

    Is there a reason you are using g_new0 instead of just new?

    State *data = new State;
    ...   // use data
    delete data;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys check this website on FF and Chrome For some reason(s), jQuery isn't working
For some reason this isn't working? I want to fill the ul#list with some
can someone please tell me why this isn't working? For some reason I need
for some reason this code isn't working in viewDidLoad , but will work in
For some reason this isn't working - maybe I need to escape some of
So this is a silly question but for some reason this isn't working for
For some reason this script isn't working in Firefox: document.onkeydown=function keypress(e) { if (e.keyCode
Ok... First off, I know this isn't a new question. But, for some reason
this is strange, for some reason this paypal isn't picking up my shipping_1 value,
For some reason, my :hover isn't working. Here's my CSS code: .image:hover { border:#000000;

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.