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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:51:28+00:00 2026-05-12T08:51:28+00:00

Greetings, everyone! Examining my own code, I came up to this interesting line: const

  • 0

Greetings, everyone!

Examining my own code, I came up to this interesting line:

const CString &refStr = ( CheckCondition() ) ? _T("foo") : _T("bar");

Now I am completely at a loss, and cannot understand why it is legal. As far as I understand, const reference must be initialized, either with r-value or l-value. Uninitialized references cannot exist. But ()? operator executes a CheckCondition() function before it assigns value to the reference. I can see now, that while CheckCondition() is executed, refStr exists, but still not initialized. What will happen if CheckCondition() will throw an exception, or pass control with a goto statement? Will it leave the reference uninitialized or am I missing something?

  • 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-12T08:51:28+00:00Added an answer on May 12, 2026 at 8:51 am

    Simpler example: const int x = foo();

    This constant too has to be initialized, and for that foo() needs to be called. That happens in the order necessary: x comes into existance only when foo returns.

    To answer your additional questions: If foo() would throw, the exception will be caught by a catch() somewhere. The try{} block for that catch() surrounded const int x = foo(); obviously. Hence const int x is out of scope already, and it is irrelevant that it never got a value. And if there’s no catch for the exception, your program (including const int x) is gone.

    C++ doesn’t have random goto‘s. They can jump within foo() but that doesn’t matter; foo() still has to return.

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

Sidebar

Related Questions

Greetings everyone. This is my first question here at stackoverflow so please bear with
Greetings everyone, going to need some help in clearing this exception. I get the
Greetings, I'm trying to find either a free .NET library or a command-line executable
Greetings, The VBA code below will create an Excel QueryTable object and display it
Greetings, currently I am refactoring one of my programs, and I found an interesting
Greetings everyone. Having an issue compiling my script containing the following function. Three errors
Greetings everyone. I'm in need of some experiance here as how to deal with
Greetings Everyone. I'm currently trying to compile a multiple-language program (C, C++ and FORTRAN)
Greetings Everyone. I'm currently writing a multi-language programe in C, C++ and fortran on
Greetings everyone: I would love to get some information from a huge collection of

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.