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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:30:41+00:00 2026-06-05T12:30:41+00:00

I was seeing some code and definition some where, like class A { public:

  • 0

I was seeing some code and definition some where, like

 class A {
       public:
              int a,b;
 };

 main() {
        A a;
        std::cout<<"Test output "<<&A::a<<" "<<&A::b<<std::endl;
 }

 Output
       1 1

What I dont understand is a and b are not static members of A, but when they are accessed like a static member it gives an error, but when accessing the address of it like a static member prints 1. Is there a special meaning behind it, coz I have no idea why it is needed and why it works this way. Thanks.

  • 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-05T12:30:43+00:00Added an answer on June 5, 2026 at 12:30 pm

    The expression &A::a when a is a non-static member returns a pointer-to-member-object (or pointer-to-member-function if a were a function). One can use them like this:

    A a;
    a.a = 1;
    a.b = 2;
    
    int (A::*) some_int_member_of_a = &A::a;
    std::cout << a.*some_int_member_of_a; // prints 1
    
    a.*some_int_member_of_a = 5;
    std::cout << a.*some_int_member_of_a; // now prints 5
    

    The stream output operation is not defined for pointer-to-member values, but there is a conversion from them to bool which is what’s getting printed in your output.

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

Sidebar

Related Questions

I'm seeing some code I've inherited that looks like the following: @interface SomeClass (private)
I'm working on converting some NSURLConnection code over to AFNetworking and I'm seeing a
Seeing some strange things; help is being solicited. I have a query, like so:
I'm seeing some weird behaviour debugging my C# code - I cant post my
I'm seeing a strange build bug a lot. Sometimes after typing some code we
I am trying to performance test some code. I am using a stopwatch. When
Possible Duplicate: PHP method chaining? So I can remember seeing in some code examples
I have some inherited code that I am modifying. However, I am seeing something
Refactoring some code again. Seeing some of this in one of the ASP.NET pages:
I'm seeing this in some code, and I have no idea what it does:

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.