How would you explain this difference in pointer to members of base and derived class using standard quotes?How to call a parent class function from derived class function?Pointer to class data member “::*”Purpose of Unions in C and C++Pretty-print C++ STL containersEfficient unsigned-to-signed cast avoiding implementation-defined behaviorWhy is f(i = -1, i = -1) undefined behavior?Why does the C++ linker allow undefined functions?restrict a template function, to only allow certain typesConverting a pointer-to-member-of-base to a pointer-to-member-of-derivedDoes the C++ standard allow for an uninitialized bool to crash a program?

MH370 blackbox - is it still possible to retrieve data from it?

Are Finite Automata Turing Complete?

Intuitively, why does putting capacitors in series decrease the equivalent capacitance?

Is my Rep in Stack-Exchange Form?

How to determine what is the correct level of detail when modelling?

How should I behave to assure my friends that I am not after their money?

First-year PhD giving a talk among well-established researchers in the field

Are neural networks the wrong tool to solve this 2D platformer/shooter game? Is there a proven way to frame this problem to a neural network?

How could mana leakage be dangerous to a elf?

How many codes are possible?

What do you call the action of someone tackling a stronger person?

Can a US President have someone sent to prison?

Do French speakers not use the subjunctive informally?

Should I tell my insurance company I'm making payments on my new car?

What would Earth look like at night in medieval times?

How to get cool night-vision without lame drawbacks?

Short story with brother-sister conjoined twins as protagonists?

Architecture of networked game engine

How can Charles Proxy change settings without admin rights after first time?

A player is constantly pestering me about rules, what do I do as a DM?

Why does the A-4 Skyhawk sit nose-up when on ground?

Calculating the partial sum of a expl3 sequence

How well known and how commonly used was Huffman coding in 1979?

How to append a matrix element by element?



How would you explain this difference in pointer to members of base and derived class using standard quotes?


How to call a parent class function from derived class function?Pointer to class data member “::*”Purpose of Unions in C and C++Pretty-print C++ STL containersEfficient unsigned-to-signed cast avoiding implementation-defined behaviorWhy is f(i = -1, i = -1) undefined behavior?Why does the C++ linker allow undefined functions?restrict a template function, to only allow certain typesConverting a pointer-to-member-of-base to a pointer-to-member-of-derivedDoes the C++ standard allow for an uninitialized bool to crash a program?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








7















demo:



#include<iostream>
struct A int i = 10; ;
struct B : A ;

int main()
std::cout << "decltype(&B::i) == int A::* ? " << std::boolalpha
<< std::is_same<decltype(&B::i), int A::*>::value << 'n'; //#1
A a;
std::cout << a.*(&A::i) << 'n';

std::cout << "decltype(&B::i) == int B::* ? "
<< std::is_same<decltype(&B::i), int B::*>::value << 'n'; //#2
B b;
std::cout << b.*(&B::i) << 'n';



The code prints



decltype(&B::i) == int A::* ? true
10
decltype(&B::i) == int B::* ? false
10


I used the example in [expr.unary.op]/3, where the standard says that the type of &B::i is int A::*, but that is not normative.










share|improve this question






























    7















    demo:



    #include<iostream>
    struct A int i = 10; ;
    struct B : A ;

    int main()
    std::cout << "decltype(&B::i) == int A::* ? " << std::boolalpha
    << std::is_same<decltype(&B::i), int A::*>::value << 'n'; //#1
    A a;
    std::cout << a.*(&A::i) << 'n';

    std::cout << "decltype(&B::i) == int B::* ? "
    << std::is_same<decltype(&B::i), int B::*>::value << 'n'; //#2
    B b;
    std::cout << b.*(&B::i) << 'n';



    The code prints



    decltype(&B::i) == int A::* ? true
    10
    decltype(&B::i) == int B::* ? false
    10


    I used the example in [expr.unary.op]/3, where the standard says that the type of &B::i is int A::*, but that is not normative.










    share|improve this question


























      7












      7








      7








      demo:



      #include<iostream>
      struct A int i = 10; ;
      struct B : A ;

      int main()
      std::cout << "decltype(&B::i) == int A::* ? " << std::boolalpha
      << std::is_same<decltype(&B::i), int A::*>::value << 'n'; //#1
      A a;
      std::cout << a.*(&A::i) << 'n';

      std::cout << "decltype(&B::i) == int B::* ? "
      << std::is_same<decltype(&B::i), int B::*>::value << 'n'; //#2
      B b;
      std::cout << b.*(&B::i) << 'n';



      The code prints



      decltype(&B::i) == int A::* ? true
      10
      decltype(&B::i) == int B::* ? false
      10


      I used the example in [expr.unary.op]/3, where the standard says that the type of &B::i is int A::*, but that is not normative.










      share|improve this question
















      demo:



      #include<iostream>
      struct A int i = 10; ;
      struct B : A ;

      int main()
      std::cout << "decltype(&B::i) == int A::* ? " << std::boolalpha
      << std::is_same<decltype(&B::i), int A::*>::value << 'n'; //#1
      A a;
      std::cout << a.*(&A::i) << 'n';

      std::cout << "decltype(&B::i) == int B::* ? "
      << std::is_same<decltype(&B::i), int B::*>::value << 'n'; //#2
      B b;
      std::cout << b.*(&B::i) << 'n';



      The code prints



      decltype(&B::i) == int A::* ? true
      10
      decltype(&B::i) == int B::* ? false
      10


      I used the example in [expr.unary.op]/3, where the standard says that the type of &B::i is int A::*, but that is not normative.







      c++ language-lawyer pointer-to-member






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 17 at 0:24









      Fabio Turati

      2,7975 gold badges25 silver badges42 bronze badges




      2,7975 gold badges25 silver badges42 bronze badges










      asked Jun 16 at 13:36









      AlexanderAlexander

      9854 silver badges14 bronze badges




      9854 silver badges14 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          8














          From the paragraph you link to, emphasis mine:




          If the operand is a qualified-id naming a non-static or variant member
          m of some class C with type T, the result has type “pointer to member
          of class C of type T” and is a prvalue designating C::m.




          "Some class C" means it need not be the same class as the one mentioned by the qualified-id. In this case, i is a member of A, and remains a member of A even when named by &B::i. The type of &B::i is therefore int A::*, which you can verify by the test



          std::is_same<decltype(&B::i), int A::*>::value


          According to [class.qual]/1, member lookup follows the algorithm detailed in [class.member.lookup]. It is according to the rules there, which inspect the sub-object from which the member i comes from, that the class C is determined. Since i is a member of the sub-object A, the class of the pointer to member is determined to be A.






          share|improve this answer




















          • 1





            To add some additional commentary: This follows on from the way that a pointer-to-member-of-base can be implicitly converted to pointer-to-member-of-derived (in contrast to the way that pointer-to-derived can be implicitly converted to pointer-to-base).

            – Martin Bonner
            Jun 16 at 13:55











          • I'm not convinced by your conclusion: "Some class C means .... The type of &B::i is therefore int A::*.

            – Alexander
            Jun 16 at 14:18







          • 1





            @Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.

            – StoryTeller
            Jun 16 at 14:20













          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56619345%2fhow-would-you-explain-this-difference-in-pointer-to-members-of-base-and-derived%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          8














          From the paragraph you link to, emphasis mine:




          If the operand is a qualified-id naming a non-static or variant member
          m of some class C with type T, the result has type “pointer to member
          of class C of type T” and is a prvalue designating C::m.




          "Some class C" means it need not be the same class as the one mentioned by the qualified-id. In this case, i is a member of A, and remains a member of A even when named by &B::i. The type of &B::i is therefore int A::*, which you can verify by the test



          std::is_same<decltype(&B::i), int A::*>::value


          According to [class.qual]/1, member lookup follows the algorithm detailed in [class.member.lookup]. It is according to the rules there, which inspect the sub-object from which the member i comes from, that the class C is determined. Since i is a member of the sub-object A, the class of the pointer to member is determined to be A.






          share|improve this answer




















          • 1





            To add some additional commentary: This follows on from the way that a pointer-to-member-of-base can be implicitly converted to pointer-to-member-of-derived (in contrast to the way that pointer-to-derived can be implicitly converted to pointer-to-base).

            – Martin Bonner
            Jun 16 at 13:55











          • I'm not convinced by your conclusion: "Some class C means .... The type of &B::i is therefore int A::*.

            – Alexander
            Jun 16 at 14:18







          • 1





            @Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.

            – StoryTeller
            Jun 16 at 14:20















          8














          From the paragraph you link to, emphasis mine:




          If the operand is a qualified-id naming a non-static or variant member
          m of some class C with type T, the result has type “pointer to member
          of class C of type T” and is a prvalue designating C::m.




          "Some class C" means it need not be the same class as the one mentioned by the qualified-id. In this case, i is a member of A, and remains a member of A even when named by &B::i. The type of &B::i is therefore int A::*, which you can verify by the test



          std::is_same<decltype(&B::i), int A::*>::value


          According to [class.qual]/1, member lookup follows the algorithm detailed in [class.member.lookup]. It is according to the rules there, which inspect the sub-object from which the member i comes from, that the class C is determined. Since i is a member of the sub-object A, the class of the pointer to member is determined to be A.






          share|improve this answer




















          • 1





            To add some additional commentary: This follows on from the way that a pointer-to-member-of-base can be implicitly converted to pointer-to-member-of-derived (in contrast to the way that pointer-to-derived can be implicitly converted to pointer-to-base).

            – Martin Bonner
            Jun 16 at 13:55











          • I'm not convinced by your conclusion: "Some class C means .... The type of &B::i is therefore int A::*.

            – Alexander
            Jun 16 at 14:18







          • 1





            @Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.

            – StoryTeller
            Jun 16 at 14:20













          8












          8








          8







          From the paragraph you link to, emphasis mine:




          If the operand is a qualified-id naming a non-static or variant member
          m of some class C with type T, the result has type “pointer to member
          of class C of type T” and is a prvalue designating C::m.




          "Some class C" means it need not be the same class as the one mentioned by the qualified-id. In this case, i is a member of A, and remains a member of A even when named by &B::i. The type of &B::i is therefore int A::*, which you can verify by the test



          std::is_same<decltype(&B::i), int A::*>::value


          According to [class.qual]/1, member lookup follows the algorithm detailed in [class.member.lookup]. It is according to the rules there, which inspect the sub-object from which the member i comes from, that the class C is determined. Since i is a member of the sub-object A, the class of the pointer to member is determined to be A.






          share|improve this answer















          From the paragraph you link to, emphasis mine:




          If the operand is a qualified-id naming a non-static or variant member
          m of some class C with type T, the result has type “pointer to member
          of class C of type T” and is a prvalue designating C::m.




          "Some class C" means it need not be the same class as the one mentioned by the qualified-id. In this case, i is a member of A, and remains a member of A even when named by &B::i. The type of &B::i is therefore int A::*, which you can verify by the test



          std::is_same<decltype(&B::i), int A::*>::value


          According to [class.qual]/1, member lookup follows the algorithm detailed in [class.member.lookup]. It is according to the rules there, which inspect the sub-object from which the member i comes from, that the class C is determined. Since i is a member of the sub-object A, the class of the pointer to member is determined to be A.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 16 at 13:49

























          answered Jun 16 at 13:42









          StoryTellerStoryTeller

          112k18 gold badges239 silver badges303 bronze badges




          112k18 gold badges239 silver badges303 bronze badges







          • 1





            To add some additional commentary: This follows on from the way that a pointer-to-member-of-base can be implicitly converted to pointer-to-member-of-derived (in contrast to the way that pointer-to-derived can be implicitly converted to pointer-to-base).

            – Martin Bonner
            Jun 16 at 13:55











          • I'm not convinced by your conclusion: "Some class C means .... The type of &B::i is therefore int A::*.

            – Alexander
            Jun 16 at 14:18







          • 1





            @Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.

            – StoryTeller
            Jun 16 at 14:20












          • 1





            To add some additional commentary: This follows on from the way that a pointer-to-member-of-base can be implicitly converted to pointer-to-member-of-derived (in contrast to the way that pointer-to-derived can be implicitly converted to pointer-to-base).

            – Martin Bonner
            Jun 16 at 13:55











          • I'm not convinced by your conclusion: "Some class C means .... The type of &B::i is therefore int A::*.

            – Alexander
            Jun 16 at 14:18







          • 1





            @Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.

            – StoryTeller
            Jun 16 at 14:20







          1




          1





          To add some additional commentary: This follows on from the way that a pointer-to-member-of-base can be implicitly converted to pointer-to-member-of-derived (in contrast to the way that pointer-to-derived can be implicitly converted to pointer-to-base).

          – Martin Bonner
          Jun 16 at 13:55





          To add some additional commentary: This follows on from the way that a pointer-to-member-of-base can be implicitly converted to pointer-to-member-of-derived (in contrast to the way that pointer-to-derived can be implicitly converted to pointer-to-base).

          – Martin Bonner
          Jun 16 at 13:55













          I'm not convinced by your conclusion: "Some class C means .... The type of &B::i is therefore int A::*.

          – Alexander
          Jun 16 at 14:18






          I'm not convinced by your conclusion: "Some class C means .... The type of &B::i is therefore int A::*.

          – Alexander
          Jun 16 at 14:18





          1




          1





          @Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.

          – StoryTeller
          Jun 16 at 14:20





          @Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.

          – StoryTeller
          Jun 16 at 14:20

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56619345%2fhow-would-you-explain-this-difference-in-pointer-to-members-of-base-and-derived%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?