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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:58:38+00:00 2026-05-25T21:58:38+00:00

In order to improve code readability, sometimes I use alias methods. These are basically

  • 0

In order to improve code readability, sometimes I use “alias methods”. These are basically methods that all do the same thing (at least in the base class; derived classes may do it differently) with different names, that enhance code readability for the class user depending on the context. Consider the code below for an example:

template <typename T>
class Foo {
public:

    T bar() { /* Lots of stuff here */ }

    inline T bar_alias1() { return this->bar(); }
    inline T bar_alias2() { return this->bar(); }
};

Of course, if Foo::bar() was a small function, one would simply duplicate the code in all the alias methods. However, since the code may be relatively large, code duplication should be avoided, hence why the alias methods are declared as inline. But I know that the compiler does not guarantee that any function declared as inline would actually end up being expanded at compile time.

So my question is, am I introducing any performance overhead by creating these alias methods? In the code below:

Foo<BIG_OBJECT> foo;
BIG_OBJECT bo1 = foo.bar();
BIG_OBJECT bo2 = foo.bar_alias1();

Would calling foo.bar() be faster than calling foo.bar_alias1() assuming the object being passed is relatively large? Are there redundant copies of the object being made when Foo::bar_alias1() calls Foo::bar()?

I’m using Visual Studio 2010 as my compiler.

  • 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-25T21:58:38+00:00Added an answer on May 25, 2026 at 9:58 pm

    Assuming the aliased functions are inlined – and they should given the size.
    There shouldn’t be any performance overhead. The code-size won’t increase either if the compiler decides to omit the function code and inline all calls to it.

    (I’m referring to the inlining of bar_alias1(), bar() itself won’t necessarily be inlined if it’s large.)

    However, this doesn’t apply if the functions are virtual.

    In C, I would do this more directly with preprocessor, but I’m not sure how appropriate that is in C++.

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

Sidebar

Related Questions

I’m looking at ways to improve the consistency, brevity, and readability of some code
In order to improve type safety in some C library code, I got the
In order to improve my open source project, I need testers. I have created
In order to improve performance reading from a file, I'm trying to read the
I'm trying to 'AJAX-ify' my site in order to improve the UI experience. In
In order to fully use LinqToSql in an ASP.net 3.5 application, it is necessary
I'm trying to do something that is fairly simple, but my code looks terrible
I've been doing some performance testing in order to improve the performance of a
Ok, before you review the code below, I know that it is AWFUL. It's
HI All I was hoping someone could help me improve a query I have

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.