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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:52:51+00:00 2026-06-11T20:52:51+00:00

I have an enum as a public memebr of a class as follows class

  • 0

I have an enum as a public memebr of a class as follows”

class myClass
{
    public:
        enum myEnum
        {
            myEnum1,
            myEnum2
        };
};

I also declare a constructors, a public parameterized one as follows:

myClass(myEnum);

I define the same outside the classs definition as follows:

myClass :: myClass(myEnum E)
{
}

How do I initialise myEnum with default arguments?

I tried:

i)

myClass :: myClass(myEnum E = 0); //to int error

ii)

myClass :: myClass(myEnum E = {0}); //some error

iii)

myClass :: myClass(myEnum E = {0, 1}); //some error

One thing I still don’t seem to understand.

How do I pass enum values to the constructor. I still get an error. And, I need to do it this way:

derived(arg1, arg2, arg3, enumHere, arg4, arg5); //call

Function definition:

derived(int a, int b, int c, enumHere, int 4, int 5) : base(a, b);

Where am I supposed to initialise the enum, as one of the answers belowe do it?

  • 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-11T20:52:52+00:00Added an answer on June 11, 2026 at 8:52 pm

    Seems like you’ve mistaken type declaration with field. In your class myEnum is declaration of type, and class itself does not hold any field of that type.

    Try this:

    class myClass
    {
        public:
            enum myEnum
            {
                myEnum1,
                myEnum2
            } enumField;
    };
    

    Then, your constructor should use member initialization:

    myClass::myClass() : enumField(myEnum1) {};
    

    If you want parametrized constructor:

    myClass::myClass(myEnum e) : enumField(e) {};
    

    If you want parametrized constructor with default argument:

    myClass(myEnum e = myEnum1) : enumField(e) {};
    

    If you want to use aforementioned constructor in derived class:

    myDerived(myEnum e) : myClass(e) {};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following enum public enum myEnum { ThisNameWorks, This Name doesn't work
I have a large enum declared in my class public enum CarMaker{ Honda, Toyota,
I have enum class public enum CommandEnum { ADD_ITEM { { this.command = new
I have a problem with the following code: class SymmetryTypes { public: enum Type
I have an enum: public enum Action { Remove=1, Add=2 } And a class:
i have enum public enum TypeImage { Img=0, Thumb=1 } i want in view
I have enum like this [Flags] public enum Key { None = 0, A
I have enum like this: public enum ObectTypes { TypeOne, TypeTwo, TypeThree, ... TypeTwenty
I have an enum : public enum Enumeration { A, B, C } And
I have an enum: public enum baseKey : uint { HKEY_CLASSES_ROOT = 0x80000000, HKEY_CURRENT_USER

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.