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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:35:24+00:00 2026-05-24T05:35:24+00:00

a bit of a noob problem. Inside a class called ‘cell’, I have an

  • 0

a bit of a noob problem. Inside a class called ‘cell’, I have an enum ‘Example’ say

  typedef enum Example
  {
      E1=0,
      E2,
      E3,
      E4
  };
  Example inputValueE;

Also I have a function inside class as follows

  void evolveE(Example type_);

Outside the class, I attempt to define the function for several types as follows

void cell::evolveE(Example type_ = E1){****some stuff****;};
void cell::evolveE(Example type_ = E2){****some diff stuff****;}; ***etc***

I’ve played around with these a bit but with no luck. The problem is i’m not allowed to redefine the same function. I was going to use the switch-case type command which is always backup although i’m pretty sure there is a more elegant way to do this

Any help is much appreciated.

  • 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-24T05:35:26+00:00Added an answer on May 24, 2026 at 5:35 am

    When overloading a function (providing more than one function with the same name in a class), you need to provide a different set of argument types to each function like this:

    void cell::evolveE(Example type_){****some stuff****;}
    void cell::evolveE(OtherExample size_){****some diff stuff****;}
    

    Notice that here, one function takes an argument of type Example and the other takes an argument of type OtherExample. Although you provide different default values in the function you are trying to overload, both functions take the same argument type and so the compiler has no way of telling the difference between them.

    You could use a switch although I would prefer an if/else because it is less prone to bugs.

    If the Example enum is really determining the type of your class you could use polymorphism. It is a very elegant feature of OOP. Then you could have something like this:

    class cell
    {
        ...
        virtual void evolveE() = 0;
    };
    
    class E1cell : public cell
    {
        ...
        void evolveE()
        {
            // some stuff
        }
    };
    
    class E2cell : public cell
    {
        ...
        void evolveE()
        {
            // some diff stuff
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

bit of noob question regarding .Net and C#. I have a function that registers
A bit of a noob question here... I have a javascript function on a
Please excuse me if this is a bit of a noob issue: I have
I am a bit of a noob still with rails, but I am running
i think this is a bit of a noob question, but here goes. I
Apologies for this question but I am a bit of a noob with Delphi.
So I am creating a fading gallery and am a bit of a noob
I'm a SQL noob, and I need a little bit of help understanding the
Bit support question. Apologies for that. I have an application linked with GNU readline.
Bit of a philosophical question. If you have a public website with a site

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.