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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:33:12+00:00 2026-05-23T17:33:12+00:00

I am confused. I never seem to decide what to use, a template or

  • 0

I am confused. I never seem to decide what to use, a template or an overloaded function. Overloads need more coding. So in what cases is it preferred to use templates and in what overloaded functions?

For example, i recently had to take this decision while making a small GBA game. There were two types u16 and int and i decided to use overloaded functions.

inline void Point::Move(int x, int y) {_ix += x; _iy += y; }
inline void Point::Move(u16 x, u16 y) {_ix += (int) x; _iy += (int) y; }

should I have used a template instead? And in what cases should I use an overloaded function?

  • 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-23T17:33:13+00:00Added an answer on May 23, 2026 at 5:33 pm

    Basic Rule should be:

    Use Templates when you want to perform same functionality/Operations on different data types.

    Use overloaded functions when you want to perform different functionality/Operations on different/same data types

    Also, A good measure of when you really need a overloaded function over template is when you are making too many explicit specializations for a templated version of function.

    In your example if you performing same operations in both the versions of the functions, You should use templates, else you should use Overloaded function.

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

Sidebar

Related Questions

So I've just read Why to never use 'or die'. I am more confused
I have never code in Python and trying to switch from Javascrpt/SVG. Being confused
I have read the docs and everything but I'm very confused. I never needed
confused - given a track uri, I can get one album but possibly more
I've read a few other questions that seem similar but I'm still very confused,
So i'm a little bit confused as i've never used an enum before. I
All- I have never done this sort of thing before and am very confused.
I've been confused about core data entities. Since you never allocate them do you
I've never used Google App Engine backends and I'm very confused by lack of
So, I'm confused as to what's going on. I've never hacked on the linux

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.