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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:28:07+00:00 2026-05-25T18:28:07+00:00

Is the following safe? I know, strictly speaking, dereferencing a pointer before the thing

  • 0

Is the following safe? I know, strictly speaking, dereferencing a pointer before the thing to which it points has been properly constructed seems dangerous, but I imagine the compiler will just provide a pointer without actually doing any dereferencing. Well, I assume.

(Note: gInst doesn’t actually use the reference until much later.)

TU 1

Sys::System::System::System(const sf::VideoMode& rVM, const std::string& rSTR, unsigned long settings) :
    win(rVM, rSTR, settings),
    gInst(*this)
{

}

Header A

namespace Sys
{
    namespace System
    {
        struct System;
    }

    namespace UI
    {
        struct GUI
        {
            System::System& topl;
            MenuBar menu;

            GUI(System::System&);

            private:

            GUI();
            GUI(const GUI&);
            GUI& operator=(const GUI&);
        };
    }
}

Header B

namespace Sys
{
    namespace System
    {
        struct System
        {
            sf::RenderWindow win;
            Sys::UI::GUI gInst;
            Sys::Editor::Editor eInst;

            System(const sf::VideoMode&, const std::string&, unsigned long);

            private:

            System();
            System(const System&);
            System& operator=(const System&);
        };

        void start();
    }
}
  • 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-25T18:28:07+00:00Added an answer on May 25, 2026 at 6:28 pm

    (Note: gInst doesn’t actually use the reference until much later.)

    Then it’s completely safe. (Taking note you say “the reference”, not “the value”.)

    Compilers will just warn about it for the reason you’ve stated, but there’s nothing undefined about it, just “risky”. Note that you can often trump compiler warnings (if they bother you) with something like this:

    struct foo
    {
        foo() : b(self())
        {}
    
    private:
        foo& self() { return *this; }
    
        bar b;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is the following code safe? (I already know it compiles properly.) void Tile::clear() {
I have got the following problem since the server has safe mode turned on,
I want to know if the following class is thread safe and works perfectly
I've always thought the following should work. I get an object which I know
I'm wondering if the following (pseudo) code is safe to use. I know about
The following class is not thread-safe (as proven in Proving the following code not
I'm curious if following code would be considered safe? using (SqlConnection cn = new
How can I quickly prove that the following class is not thread-safe (as it
I was wondering if it's safe to do the following iteration to find the
For strongly-typed & type-safe solution, I have to do the following step. Create some

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.