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?
Why does a Force divides equally on a Multiple Support/Legs?
Do details of my undergraduate title matter?
Setting up the trap
Implementation of the Jacobi Symbol in C
I found a password with hashcat but it doesn't work
Why there is a red color in right side?
Why is it easier to balance a non-moving bike standing up than sitting down?
First occurrence in the Sixers sequence
What does this Swiss black on yellow rectangular traffic sign with a symbol looking like a dart mean?
How can a warlock learn from a spellbook?
Why things float in space, though there is always gravity of our star is present
How did Frodo know where the Bree village was?
In Street Fighter, what does the M stand for in M Bison?
Why do you need to heat the pan before heating the olive oil?
Would a 7805 5 V regulator drain a 9 V battery?
Why is Havana covered in 5-digit numbers in Our Man in Havana?
How is the idea of "girlfriend material" naturally expressed in Russian?
What is the most suitable position for a bishop here?
60's (or earlier) sci-fi short story about two spacecrafts exchanging plants for gold and thinking they got the better of the exchange
Is there any possible way to get these hearts as Adult Link?
What kind of chart is this?
Freewill and rewarding dogs
Is using legacy mode instead of UEFI mode a bad thing to do?
How can I ping multiple IP addresses at the same time?
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 height:90px;width:728px;box-sizing:border-box;
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
add a comment |
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
add a comment |
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
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
c++ language-lawyer pointer-to-member
edited 14 mins ago
Fabio Turati
2,75652542
2,75652542
asked 11 hours ago
AlexanderAlexander
985414
985414
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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 classC
with typeT
, the result has type “pointer to member
of classC
of typeT
” and is a prvalue designatingC::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
.
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
10 hours ago
I'm not convinced by your conclusion: "Some classC
means .... The type of&B::i
is thereforeint A::*
.
– Alexander
10 hours ago
1
@Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.
– StoryTeller
10 hours ago
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 classC
with typeT
, the result has type “pointer to member
of classC
of typeT
” and is a prvalue designatingC::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
.
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
10 hours ago
I'm not convinced by your conclusion: "Some classC
means .... The type of&B::i
is thereforeint A::*
.
– Alexander
10 hours ago
1
@Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.
– StoryTeller
10 hours ago
add a comment |
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 classC
with typeT
, the result has type “pointer to member
of classC
of typeT
” and is a prvalue designatingC::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
.
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
10 hours ago
I'm not convinced by your conclusion: "Some classC
means .... The type of&B::i
is thereforeint A::*
.
– Alexander
10 hours ago
1
@Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.
– StoryTeller
10 hours ago
add a comment |
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 classC
with typeT
, the result has type “pointer to member
of classC
of typeT
” and is a prvalue designatingC::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
.
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 classC
with typeT
, the result has type “pointer to member
of classC
of typeT
” and is a prvalue designatingC::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
.
edited 10 hours ago
answered 10 hours ago
StoryTellerStoryTeller
112k17236303
112k17236303
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
10 hours ago
I'm not convinced by your conclusion: "Some classC
means .... The type of&B::i
is thereforeint A::*
.
– Alexander
10 hours ago
1
@Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.
– StoryTeller
10 hours ago
add a comment |
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
10 hours ago
I'm not convinced by your conclusion: "Some classC
means .... The type of&B::i
is thereforeint A::*
.
– Alexander
10 hours ago
1
@Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.
– StoryTeller
10 hours ago
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
10 hours ago
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
10 hours ago
I'm not convinced by your conclusion: "Some class
C
means .... The type of &B::i
is therefore int A::*
.– Alexander
10 hours ago
I'm not convinced by your conclusion: "Some class
C
means .... The type of &B::i
is therefore int A::*
.– Alexander
10 hours ago
1
1
@Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.
– StoryTeller
10 hours ago
@Alexander - My conclusion is backed by the member lookup algorithm. And the wording of "some class" is not coincidental.
– StoryTeller
10 hours ago
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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