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

  • Home
  • SEARCH
  • 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 4602010
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:54:56+00:00 2026-05-21T23:54:56+00:00

enum ENUM(Option1,Option2,Option3); string func(ENUM x) { switch(x) { case Option1: return Option1; case Option2:

  • 0
enum ENUM(Option1,Option2,Option3);

string func(ENUM x)
{
 switch(x)
 {
  case Option1: return "Option1";
  case Option2: return "Option2";
  case Option3: return "Option3";
 }
}

This compiles and works but gives a compiler warning that not all control paths return. However isn’t the point that if you use enums properly, this isn’t the case? If another ENUM val is added, I want compilation to fail but as long as all cases are covered I want it to compile warning-free.

Is this the compiler protecting against bad casted values, is it just part of C++ and needs to be lived with?

  • 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-21T23:54:57+00:00Added an answer on May 21, 2026 at 11:54 pm

    What happens if for some reason x is neither Option1, nor Option2, nor Option3?

    Sure, you could argue that will never happen, but since the method has to return something, you have two options:

    • add a return string(""); at the end.

    • add a default to the switch that returns string("").

    As CodeGray points out, the second option is arguably better style. You could also return something other than an empty string.

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

Sidebar

Related Questions

public enum myEnum { VAL1(10), VAL2(20), VAL3(hai) { public Object getValue() { return this.strVal;
I have the following enum: public enum Status implements StringEnum{ ONLINE(on),OFFLINE(off); private String status
Given the following java enum: public enum AgeRange { A18TO23 { public String toString()
I have an enum construct like this: public enum EnumDisplayStatus { None = 1,
I want to do a method with a signature like this: Expression<Func<TSource, bool>> CreatePropertyFilter<TSource>(Expression<Func<TSource,
in java im used to extending enum values or overriding methods like this :
enum options {Yes,No}; class A{ int i; string str; options opt; }; int main{
public enum Scale2 { GOOD('C') { public char getGrade() { return grade; } },
enum MyEnum { A( 1, 2, 3, 4), B(1, 2), C(4, 5, 8, 8,
An enum in Java implements the Comparable interface. It would have been nice to

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.