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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:33:41+00:00 2026-06-06T18:33:41+00:00

While I would assume that in VC++ this would be a no brainer, it’s

  • 0

While I would assume that in VC++ this would be a no brainer, it’s still worth asking.

When creating a getter method for a class that only returns the value of a protected/private member, does the compiler optimize this call so it’s the equivalent of referencing that member without having to friend the class and without the overhead of a full method call?

  • 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-06T18:33:42+00:00Added an answer on June 6, 2026 at 6:33 pm

    Yes. Both variants compile to the same thing:

    struct test
    {
        int x;
    
        int get() const { return x; }
    };
    
    __declspec(noinline) int use_x(const test& t)
    {
        return t.x;
    }
    
    __declspec(noinline) int use_get(const test& t)
    {
        return t.get();
    }
    
    int main()
    {
        test t = { 111605 };
    
        // pick one:
        return use_x(t);
        //return use_get(t);
    }
    

    Note that it’s not as simple as always replacing t.get() with t.x, for the compiler. Consider something like this:

    t.get() += 5;
    

    This shouldn’t compile, because the result of the function call is an rvalue and += (for primitives) requires an lvalue. The compiler will check for things like that.

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

Sidebar

Related Questions

While writing code in a file that would comprise of PHP, HTML, CSS &
To simplify this posed question, assume that each cell has a Row Name and
This has been bugging me for a while. I have this ircbot that I
Question 1: Assume that i am reading XmlNodeType.Text and I would like to know
I am trying this in an XQuery (assume that doc('input:instance') does indeed return a
From this post : I would first suggest that you optimize your dependentObservable (a.k.a.
While editing .scm files it would be great if Vim would automatically put the
I would like to show loadingActivity while activity1 is executing some code (working), after
I would like to find a way to see what happens while my XAML
I would like to make one of the div's hidden while rendring. After page

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.