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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:01:11+00:00 2026-05-26T22:01:11+00:00

I want to check to see whether something is null, e.g.: string xxx(const NotMyClass&

  • 0

I want to check to see whether something is null, e.g.:

string xxx(const NotMyClass& obj) {
  if (obj == NULL) {
     //...
  }
}

But the compiler complains about this: there are 5 possible overloads of ==.

So I tried this:

  if (obj == static_cast<NotMyClass>(NULL)) {

This crashes because NotMyClass‘s == overload doesn’t handle nulls.

edit: for everyone tell me it can’t be NULL, I’m certainly getting something NULL like in my debugger:

enter image description here

  • 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-26T22:01:12+00:00Added an answer on May 26, 2026 at 10:01 pm

    In a well-formed C++ program, references are never NULL (more accurately, the address of an object to which you have a reference may never be NULL).

    So not only is the answer “no, there’s no way”, a corollary is “this makes no sense”.


    Your statement regarding C makes no sense either, since C does not have references.

    And as for Java, its “references” are more like C++ pointers in many ways, including this one.

    Comparing such specific behaviours between different languages is something of a fool’s errand.


    If you need this “optional object” behaviour, then you’re looking for pointers:

    std::string xxx(const NotMyClass* ptr) {
      if (ptr == NULL)
         throw SomeException();
    
      const NotMyClass& ref = *ptr;
      /* ... */
    }
    

    But consider whether you really need this; a decent alternative might be boost::optional if you really do.

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

Sidebar

Related Questions

I want to be able to check a string to see if it has
I want to check a time that is being entered to see whether it
I want to check whether the CSS property pointer-events ( see documentation ) is
I want to check to see if an XML document contains a 'person' element
I want to check to see if an array has - to activate a
I want to check a particular website from various locations. For example, I see
I want to check for duplicated words right next to each other, but even
I want to check whether a certain term is contained in a document. However,
How can I check whether a given string contains a certain substring, using Perl?
I want to test a given IP and login detail to see whether the

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.