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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:31:46+00:00 2026-05-11T03:31:46+00:00

Yesterday I read some code of a colleague and came across this: class a_class

  • 0

Yesterday I read some code of a colleague and came across this:

class a_class { public:     a_class() {...}     int some_method(int some_param) {...}      int value_1;     int value_2;     float value_3;     std::vector<some_other_class*> even_more_values;     /* and so on */  }   a_class a_instances[10];   void some_function()  {      do_stuff();      do_more_stuff();       memset(a_instances, 0, 10 * sizeof(a_class)); // <===== WTF?  } 

Is that legal (the WTF line, not the public attributes)? To me it smells really, really bad… The code ran fine when compiled with VC8, but it throws an ‘unexpected exception’ when compiled with VC9 when calling a_instances[0].event_more_values.push_back(whatever), but when accessing any of the other members. Any insights?

EDIT: Changed the memset from memset(&a_instances... to memset(a_instances.... Thanks for pointing it out Eduard.
EDIT2: Removed the ctor’s return type. Thanks litb.

Conclusion: Thanks folks, you confirmed my suspicion.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T03:31:46+00:00Added an answer on May 11, 2026 at 3:31 am

    This is a widely accepted method for initialization for C structs.
    In C++ it doesn’t work ofcourse because you can’t assume anything about vectors internal structure. Zeroing it out is very likely to leave it in an illegal state which is why your program crashes.

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

Sidebar

Related Questions

Im searching this since yesterday. I've got on many Activities some piece of code
Yesterday I made a small script with some help to read .csv files. I
Ok so yesterday I had some trouble with this error, turned out I just
I've just started learning how to use pygame yesterday. I was read this one
This has to do with a question I read yesterday: How to determine how
I'm helping out a colleague on this one so if I'm missing some details
This question is in relation to a question I posted yesterday. The link -http://stackoverflow.com/questions/12636348/how-to-add-a-different-class-to-the-same-class-in-jquery
Initial Question Yesterday i read about ECMAScript 5 Object.create() And I wanted to start
Yesterday I updated to firefox 13 and I notice that this property is not
further developing the code from yesterday ( seg fault caused by malloc and sscanf

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.