Independent Referance

// IndependentRefrance.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{
int a;
int &ref = a; // independent reference
a = 10;
std::cout << a << " " << ref << "\n";
ref = 100;
std::cout << a << " " << ref << "\n";
int b = 19;
ref = b; // this puts b's value into a
std::cout << a << " " << ref << "\n";
ref--; // this decrements a
// it does not affect what ref refers to
std::cout << a << " " << ref << "\n";
return 0;
}

Comments

Popular posts from this blog

Smart Pointers in C++ and How to Use Them

Operator Overloading in C++

How would you read in a string of unknown length without risking buffer overflow