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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:17:36+00:00 2026-05-24T09:17:36+00:00

I was having a problem getting a function to accept an enum as a

  • 0

I was having a problem getting a function to accept an enum as a return-type. In the code below there’s an enum:

Status{ DEAD, WOUNDED, HEALTHY }

and a function with Status as a return type:

Status getStatus();

Header Code:

class Discovery
{
public:
    void doCombat( int );
    void setCombatThreshold( int );
    void setHealth( int );
    void setStatus( int );
    Status getStatus();
private:
    enum Status { DEAD, WOUNDED, HEALTHY };
    Status charStatus;
    int yourHealth;
    int combatThreshold;
};

Initially the associated function definition read:

Status Discovery::getStatus()
{
    switch ( charStatus )
    {
    case DEAD:
        return DEAD;
        break;
    case WOUNDED:
        return WOUNDED;
        break;
    case HEALTHY:
        return HEALTHY;
        break;
    };
}

I found this answer: returning enum from function in C++ base class which helped me realize I really needed the first line of the function to read:

Discovery::Status Discovery::getStatus()

But, I was still receiving a ‘missing type specifier’ error for my header code. I realized that having my ‘enum Status’ declaration under the private access-specifier might be making the difference, so I moved it to the public access-specifier in my header code. It worked! But I’d like some elucidation on why it wouldn’t work under the private access-specifier. What I’ve managed to find elsewhere is:

Objects of the class cannot access private data members.

My interpretation of what happened being – with the enum-type definition under the private access-specifier, the function (and eventually an object calling that function) couldn’t possibly access ‘understand’ my enum-type, and therefore accept it as a return type.

But – if that’s the case, why am I allowed to return variables declared under the private access-specifier with the same problem? Is it because their types are already understood elsewhere, and so the program has no problem accepting them?

  • 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-24T09:17:37+00:00Added an answer on May 24, 2026 at 9:17 am

    Status is defined after it’s used. Move status up before the get method.

    If you plan to use the enum outside of the class you will want to move the enum into public scope.

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

Sidebar

Related Questions

Having a problem getting a TreeView control to display node images. The code below
I'm having a problem getting a change event to register with the following code:
I have the following code, however im having a problem getting window.location to work
I'm having a problem. I have this code: setInterval(function() { $.ajax({ url: url, success:
I am having a problem with getting my JQuery javascript code to apply to
I am having a problem getting the javascript code to work inside an AJAX
I'm having a problem getting the root URL with this PHP function I composed.
I'm having a problem getting the back button function to work in Rhomobile. I've
I am having problem getting my tooltip to work when using the jQuery load()
I am having a problem getting a list of fields from a query defined

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.