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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:36:15+00:00 2026-05-16T17:36:15+00:00

I am trying to write a function that will check if an object exists:

  • 0

I am trying to write a function that will check if an object exists:

bool UnloadingBay::isEmpty() {
    bool isEmpty = true;
    if(this->unloadingShip != NULL) {
        isEmpty = false;
    }
    return isEmpty;
}

I am pretty new to C++ and not sure if my Java background is confusing something, but the compiler gives an error:

UnloadingBay.cpp:36: error: no match for ‘operator!=’ in ‘((UnloadingBay*)this)->UnloadingBay::unloadingShip != 0’

I can’t seem to figure out why it doesn’t work.

Here is the declaration for class UnloadingBay:

class UnloadingBay {

    private:
        Ship unloadingShip;

    public:
        UnloadingBay();
        ~UnloadingBay();

        void unloadContainer(Container container);
        void loadContainer(Container container);
        void dockShip(Ship ship);
        void undockShip(Ship ship);
        bool isEmpty();

};
  • 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-16T17:36:16+00:00Added an answer on May 16, 2026 at 5:36 pm

    It sounds like you may need a primer on the concept of a “variable” in C++.

    In C++ every variable’s lifetime is tied to it’s encompassing scope. The simplest example of this is a function’s local variables:

    void foo() // foo scope begins
    {  
        UnloadingShip anUnloadingShip; // constructed with default constructor
    
        // do stuff without fear!
        anUnloadingShip.Unload();
    } // // foo scope ends, anything associated with it guaranteed to go away
    

    In the above code “anUnloadingShip” is default constructed when the function foo is entered (ie its scope is entered). No “new” required. When the encompassing scope goes away (in this case when foo exits), your user-defined destructor is automatically called to clean up the UnloadingShip. The associated memory is automatically cleaned up.

    When the encompassing scope is a C++ class (that is to say a member variable):

    class UnloadingBay
    {
       int foo;
       UnloadingShip unloadingShip;
    };
    

    the lifetime is tied to the instances of the class, so when our function creates an “UnloadingBay”

    void bar2()
    {
        UnloadingBay aBay; /*no new required, default constructor called,
                             which calls UnloadingShip's constructor for
                             it's member unloadingShip*/
    
        // do stuff!
    }  /*destructor fires, which in turn trigger's member's destructors*/
    

    the members of aBay are constructed and live as long as “aBay” lives.

    This is all figured out at compile time. There is no run-time reference counting preventing destruction. No considerations are made for anything else that might refer to or point to that variable. The compiler analyzes the functions we wrote to determine the scope, and therefore lifetime, of the variables. The compiler sees where a variable’s scope ends and anything needed to clean up that variable will get inserted at compile time.

    “new”, “NULL”, (don’t forget “delete”) in C++ come into play with pointers. Pointers are a type of variable that holds a memory address of some object. Programmers use the value “NULL” to indicate that a pointer doesn’t hold an address (ie it doesn’t point to anything). If you aren’t using pointers, you don’t need to think about NULL.

    Until you’ve mastered how variables in C++ go in and out of scope, avoid pointers. It’s another topic entirely.

    Good luck!

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

Sidebar

Related Questions

I am trying to write a function that will allow me to browse for
I'm trying to write a function that will: If there is no region selected,
i am trying to write a function that will make DataRow[column] return nullable typed
I'm trying to write a function that will let me red-shift or blue-shift a
I am trying to write a function that will filter a list of tuples
I am trying to write a function that will: Disable the submit button when
I am trying to write a function that will randomly return an (x,y) co-ordinates
I'm trying to write a function that will return all the available cars for
I am trying to write a function that will convert a generic list to
I'm trying to write a short function that will let me quickly read in

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.