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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:22:47+00:00 2026-06-18T02:22:47+00:00

(not rubbish only if zero initialized as static scope member.) and it works as

  • 0

(not rubbish only if zero initialized as static scope member.) and it works as expected on GCC!(((

So for code like:

#include <iostream>
#include <boost/shared_ptr.hpp>

namespace SP
{
    // enums
    enum EnumMessage {
        EnumMessage_EventBase = 0,
        EnumMessage_EventServiceBase = 1,
        EnumMessage_OperationBase = 2
    };

    class Message;

    // define proxy class
    class Message  {
    public:
        EnumMessage _MessageCode;
    };

    class Parent : public Message {
    public:
        int _ServiceId;
        int _CallbackId;
    };

    class Child : public Parent {
    public:
        std::string _Debug;
    };

    class AnotherChild : public Parent {
    public:
        int _UserId;
    };
}

using namespace SP;

int main() {
    //OK
    static Child staticScopeChild = Child();
    boost::shared_ptr<Parent> ptrParent(new Parent());
    boost::shared_ptr<AnotherChild> ptrChild2(new AnotherChild());

    //Bad
    Child scopeChild = Child();
    boost::shared_ptr<Child> ptrChild(new Child());


    std::cout << "static " << staticScopeChild._MessageCode 
        << std::endl << "vs scope " << scopeChild._MessageCode 
        << std::endl << "vs pointer " << ptrChild->_MessageCode 
        << std::endl << "vs parent class pointer: " << ptrParent->_MessageCode 
        << std::endl << "vs another parent child: " << ptrChild2->_MessageCode <<std::endl;
    std::cin.get();
    return 0;
}

where all classes are generally PODs (ints, enums) I get next output:

static 0
vs scope -858993460
vs pointer -842150451
vs parent class pointer: 0
vs another parent child: 0

while I expected all to be 0!

Why can such thing happen?

  • 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-18T02:22:49+00:00Added an answer on June 18, 2026 at 2:22 am

    It appears to be a compiler bug: according to this report members of base classes are not zero-initialised during value-initialisation of the derived class.

    As far as I can see, there is nothing wrong with your code, and all class members should be zero-initialised on a conforming C++03 or C++11 compiler.

    I guess your options are:

    • make the classes more POD-like by avoiding inheritance; or
    • add default constructors to any base classes to explicitly zero-initialise all members; or
    • use a less broken compiler.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so this piece of code works fine in the Debug but not in
Not to sound like a koan, but just wondering if there are definite rules
when i print this characters in facebook status it makes a rubbish like ‎!̸̶͚͖͖̩̻̩̗͍̮̙̈͊͛̈͒̍̐ͣͩ̋ͨ̓̊̌̈̊́̚͝͠ͅ
I have a very annoying bug, code generation tool has generated like 20,000 lines
Sorry about the rubbish question title. I have a table SET_DEFINITIONS like this: SETKEY
The simple script below returns a bunch of rubbish. It works for most websites,
Sorry for the slightly rubbish title. I could not think how to describe this
Not ever sure if it can be done, but is it possible to use
Not crazy about the way Xcode 4.2 has laid out the files on disk.
Not able to download artifacts from central maven repository. <mirrors> <!-- mirror | Specifies

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.