65,187
社区成员




const int & ival1 = 0;
const int * const pival = &ival1;
const int * const &rpival = &ival1;
cout << typeid(pival).name() << endl; // Output: int const * ??
cout << typeid(rpival).name() << endl; // Output: int const * ??
//pival++;
int i = 0;
int &ri = i;
cout << typeid(&ri).name() << endl; // int const *
#include "stdafx.h"
int main(int argc, char* argv[])
{
int a=1;
int &b=a;
int c=3;
printf("%d\n", b);
1[&c]=int(&c);
printf("%d\n", b);
return 0;
}
#include "stdafx.h"
int main(int argc, char* argv[])
{
int a=1;
int &b=a;
int c=3;
printf("%d\n", b);
1[&c]=int(&c);
printf("%d\n", b);
return 0;
}
int i = 0;
int &ri = i;
cout << typeid(&ri).name() << endl; // int const *
const int i = 0;
const int &ri = i;
cout << typeid(&ri).name() << endl;
int i = 0;
int &ri = i;
cout << typeid(&ri).name() << endl; // int const *
我觉得 typeid(&ri).name(): int * const 更符合引用的语义。
#include "stdafx.h"
int main(int argc, char* argv[])
{
int a=1;
int &b=a;
int c=3;
printf("%d\n", b);
1[&c]=int(&c);
printf("%d\n", b);
return 0;
}
#include "stdafx.h"
int a;
int &b=a;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
return b;
}
; COMDAT _$E1
_TEXT SEGMENT
_$E1 PROC NEAR ; COMDAT
; 6 : int &b=a;
push ebp
mov ebp, esp
sub esp, 64 ; 00000040H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-64]
mov ecx, 16 ; 00000010H
mov eax, -858993460 ; ccccccccH
rep stosd
mov DWORD PTR ?b@@3AAHA, OFFSET FLAT:?a@@3HA ; b, a
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
_$E1 ENDP
_TEXT ENDS
PUBLIC _WinMain@16
; COMDAT _WinMain@16
_TEXT SEGMENT
_WinMain@16 PROC NEAR ; COMDAT
; 12 : {
push ebp
mov ebp, esp
sub esp, 64 ; 00000040H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-64]
mov ecx, 16 ; 00000010H
mov eax, -858993460 ; ccccccccH
rep stosd
; 13 : // TODO: Place code here.
; 14 :
; 15 : return b;
mov eax, DWORD PTR ?b@@3AAHA ; b
mov eax, DWORD PTR [eax]
; 16 : }
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 16 ; 00000010H
_WinMain@16 ENDP
_TEXT ENDS
END