Referencje to aliasy nie wskaźniki !

Zdanie w tytule potwierdza taki o to kod
[pawn]#include < iostream >

int main( ){
int iTestVariable = 0;

int & iReference = iTestVariable;
int * iPointer = &iTestVariable;

std::cout << „Variable \tAddress\t” << &iTestVariable << „\n”
<< „Reference \tAddress\t” << &iReference << „\n”
<< „Pointer \tAddress\t” << &iPointer << std::endl;

std::system( „pause” );
}[/pawn]
Download main.zip

Jak widzimy zmienna iTestVariable oraz referencja do niej ( iReference ) mają ten sam adres więc jest to ten sam „obiekt” pod różnymi nazwami.
Zaś wskaźnik jest kompletnie innym obiektem który przechowuję tylko adres zmiennej.

Jeden komentarz o “Referencje to aliasy nie wskaźniki !

Dodaj komentarz

Witryna wykorzystuje Akismet, aby ograniczyć spam. Dowiedz się więcej jak przetwarzane są dane komentarzy.