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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:53:10+00:00 2026-05-14T04:53:10+00:00

I have a header file with all the enums listed (#ifndef #define #endif construct

  • 0

I have a header file with all the enums listed (#ifndef #define #endif construct has been used to avoid multiple inclusion of the file) that I use in multiple cpp files in my application.One of the enums in the files is

enum StatusSubsystem {ENABLED,INCORRECT_FRAME,INVALID_DATA,DISABLED};

There are functions in the application delcared as

ShowStatus(const StatusSubsystem&);

Earlier in the application when I made calls to the above function like

ShowStatus(INCORRECT_FRAME);

my application used to compile perfectly. But after some code was added The compilation halts giving the following error:

File.cpp:71: error: invalid conversion from `int' to `StatusSubsystem'
File.cpp:71: error:   initializing argument 1 of `void Class::ShowStatus(const StatusSubsystem&)

I checked the code for any conflicting enums in the new code and it looked fine.

My Question is what is wrong with the function call that compiler shows as erroneous?

For your reference the function definition is:

void Class::ShowStatus(const StatusSubsystem& eStatus)
{

   QPalette palette;
   mStatus=eStatus;//store current Communication status of system 
   if(eStatus==DISABLED)
   {
     //select red color for  label, if it is to be shown disabled
     palette.setColor(QPalette::Window,QColor(Qt::red));
     mLabel->setText("SYSTEM");

   }
   else if(eStatus==ENABLED)
   {
      //select green color for label,if it is to be shown enabled
      palette.setColor(QPalette::Window,QColor(Qt::green));
     mLabel->setText("SYSTEM");

   }
   else if(eStatus==INCORRECT_FRAME)
   {
      //select yellow color for  label,to show that it is sending incorrect frames
      palette.setColor(QPalette::Window,QColor(Qt::yellow));
      mLabel->setText("SYSTEM(I)");

   }
   //Set the color on the  Label
   mLabel->setPalette(palette);
}

A strange side effect of this situation is it compiles when I cast all the calls to ShowStatus() as

ShowStatus((StatusSubsystem)INCORRECT_FRAME);

Though this removes any compilation error, but a strange thing happens. Though I make call to INCORRECT_FRAME above but in function definition it matches with ENABLED. How on earth is that possible? Its like while passing INCORRECT_FRAME by reference, it magically converts to ENABLED, which should be impossible. This is driving me nuts.

Can you find any flaw in what I am doing? or is it something else?

The application is made using C++,Qt-4.2.1 on RHEL4.

Thanks.

  • 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-14T04:53:11+00:00Added an answer on May 14, 2026 at 4:53 am

    You should take the enum by value, rather than by const reference. It’s small enough to fit into an int, so there is no performance penalty or anything like it.

    But, from what you’re describing, it sounds like somebody has #defined INCORRECT_FRAME to 0 elsewhere. You should put something like the following in the line above it:

    #ifdef INCORRECT_FRAME
    #error Whoops, INCORRECT_FRAME already defined!
    #endif
    

    BTW, the #ifndef thingy (for your header files) is called an include guard. 🙂

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

Sidebar

Related Questions

I have a header file like this: #ifndef __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #define __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #ifdef _DEBUG //
Let's say I have a header file called inclusions.h that has all the #include
I have a header file that has some static variables for all of my
I have a header file variable.h where i declare all my global variable.Then i
We have a web application with a common header file for all pages. We
I have a header file, lets say Common.h, that is included in all of
I have all the class definitions in a header file: ModelModule.h. I have provided
I have a header file in a managed DLL project like so: Enums.h: #pragma
I have put all the structures in a header file named structure.h : struct
Following the post , if I have header file,which has some functions implementations 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.