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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:34:34+00:00 2026-06-04T08:34:34+00:00

Let’s say I’m building a simple class that prints some text on the screen,

  • 0

Let’s say I’m building a simple class that prints some text on the screen, and it has the possibility to change the colors of the text.

myclass a("this is the text");
a.setColor("green");

I’m still learning C++ and I recently got introduced to enum and thought I’d give it a try. I was wondering if it is a good practice to use enum types in interface functions like the above setColor?

What are the advantages or disadvantages of using enum classes in interface functions? Are there cases where they are more applicable than and are there case where they are bad to use?

What if I want to combine properties? E.g.

a.setAttribute("bold reverse");

I don’t know if interface is the correct term for what I want to describe: the functions that a user of my class would end up using.

  • 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-06-04T08:34:36+00:00Added an answer on June 4, 2026 at 8:34 am

    In your case, there are (at least) two advantages:

    • No need to parse the string at run-time, leading to higher efficiency. You can use an enum variable directly in a switch statement.
    • An enum is (to some extent) self-documenting, the user of your code has to work hard to provide an invalid value.

    One potential “disadvantage” is in the case where the colour string has come from e.g. run-time userinput (they’ve typed into a textbox or something). You will need to parse this string and convert it into an enum. But it’s not really a disadvantage, because you’ll need to do this anyway. Best practice is for the user-interface logic to validate the string and convert to the enum at the earliest opportunity.

    What if I want to combine properties?

    I can think of at least three options:

    • Use multiple calls to setAttribute.
    • Pass an array of attributes.
    • Define each enum value to be a power-of-two, and then you can combine enums with |.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's say I have a class that does some calculations. This set of calculations
Let's say i have this block of code, <div id=id1> This is some text
Let's say I have the string: hello world; some random text; foo; How could
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let's say I want to have some kind of a cache that did something
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's assume that we are building a high traffic site that will be used
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2

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.