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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:58:48+00:00 2026-05-16T08:58:48+00:00

Sometimes, I felt method overloading may create confusion. class a { public: void copy(float

  • 0

Sometimes, I felt method overloading may create confusion.

class a {
public:
    void copy(float f);
    void copy(double d);
};

a me;
me.copy(1.2); // Not obvious at the first sight on which version we are calling.

A workaround on this is.

class a {
public:
    void copyFloat(float f);
    void copyDouble(double d);
};

However, having method with different name, to perform same functionality doesn’t seem a good idea as well. May I know, what do you consider, to choose among method overloading, or method with different naming?

  • 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-16T08:58:49+00:00Added an answer on May 16, 2026 at 8:58 am

    Overloading for sure.

    Okay, so it’s not “obvious” which function gets called (arguable)…so what? You don’t care that it can take different types of parameters, it just needs to do its thing. If you have different behavior based on different overloads, you’ve abused overloads, not pointed out a flaw in them.

    An example of abusing overloads:

    // good:
    struct has_properties
    {
        void property1(float); // set property1, which happens to be a float
        void property2(int); // set property2, which happens to be an int
    };
    
    // bad:
    struct has_properties
    {
        void property(float); // set property1, abusing that it's a float
        void property(int); // set property2, abusing that it's an int
    };
    

    Hopefully you see the problem here. If two functions have the same name, they should do the same thing.

    Even better, if you’re merely trying to allow the possibility for operating on different types, just use a template. (This arguably is a form of overloading.)

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

Sidebar

Related Questions

Sometimes when reading a socket from the TcpClient class , the stream comes in
Sometimes, not often, I see these lines in the error log: [Sun Feb 20
Sometimes I'm getting the FB is not defined issue when loading the http://connect.facebook.net/en_US/all.js I've
Sometimes when I'm developing I may prefer to quickly inline classes, interfaces and/or enums
sometimes web-fonts don't load (for instance if hosted on google fonts) and fallbacks may
Sometimes an iterable might be not subscriptable. Say the return from itertools.permutations : ps
Sometimes I find myself writing really simple wrappers, where a wrappers method directly corresponds
Sometimes you come by Zip files with file or directory with some unrecognized characters
Sometimes i face the following problem : string txt = con.Request.Params[Par_name].ToString();//the original par value
Sometimes I feel the urge to put some more expressiveness in my git commit

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.