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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:14:41+00:00 2026-05-31T14:14:41+00:00

The following program is in 5 files. The output is 0 32, instead of

  • 0

The following program is in 5 files. The output is 0 32, instead of 14 32 and therefore an object is constructed without calling the constructor. How is this possible?

character.h:

#ifndef CHARACTER_H
#define CHARACTER_H 

class Character
{
public:
    Character() {}

    class Settings
    {
    public:
        int size_;
        Settings():
            size_(14)
        {}
    };
    const static Settings DEFAULT_SETTINGS;
};

#endif // CHARACTER_H

character.cpp:

#include "character.h"

const Character::Settings Character::DEFAULT_SETTINGS;

word.h

#ifndef WORD_H
#define WORD_H

#include <iostream>

#include "character.h"

class Word 
{
public:
    Word() {}

    class Settings
    {
    public:
        Character::Settings characterSettings_;
        int length_;

        Settings():
            length_(32)
        {
            characterSettings_ = Character::DEFAULT_SETTINGS;
        }
    };

    static const Settings DEFAULT_SETTINGS;

    void write(Settings settings = DEFAULT_SETTINGS) // this default parameter is 
                                                     // constructed without a   
                                                     // constructor call
    {
        std::cout << settings.characterSettings_.size_ << std::endl;
        std::cout << settings.length_ << std::endl;
     }
 };

#endif // WORD_H

word.cpp

#include "word.h"

const Word::Settings Word::DEFAULT_SETTINGS;

main.cpp

#include "word.h"

int main(int argc, char *argv[])
{
    Word member;
    member.write();
    return 1;
}
  • 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-31T14:14:42+00:00Added an answer on May 31, 2026 at 2:14 pm

    That’s called the static initialization fiasco. Basically there is no fixed order on the execution of the constructors for variables with static duration defined in different translation units. In this particular case the Word::DEFAULT_SETTINGS has been constructed before the Character::DEFAULT_SETTINGS and thus has read the 0 value that variables of static duration have before being actually initialized. If you want to see something interesting, dump the contents of Character::DEFAULT_SETTINGS and you will see that strangely enough it is 14

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

Sidebar

Related Questions

I generate a coverage.xml output file with the following command. C:\Program Files\NCover\NCover.Console.exe //reg //w
Why gives the following Windows 7 .cmd command script: set SUN_JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_17 if
I could use the following: <fileset dir=C:\Program Files\eclipse\plugins\myplugin> <include name=extraStuff.jar /> </fileset> But that
The following program can run successfully: class Simple(object): def __init__(self, name): self.name = name
I'm trying to do this: cmd.exe /C C:\Program Files\Somewhere\SomeProgram.exe > C:\temp\Folder Containing Spaces\SomeProgram.out However,
When I write the following program: file 1: #include <stdio.h> int global; void print_global1()
Consider the following simple C program that read a file into a buffer and
the following is a line from a python program that calls the demo.exe file.
The following program is very simple: it outputs a single dot each half a
Consider following program: static void Main (string[] args) { int i; uint ui; i

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.