Wednesday, January 09, 2008

Little Sugar: C++ references

C++ references are a variant of const pointers that always point to something .

Now consider

string s1("abc");

string s2("def");

string & refTos1 = s1;

Now refTosi points to s1.

Even after refTos1 = s2. Its still points to s1 . But the value of s1 is now changed from "abc" to "def"

2 comments:

Stargazer said...

This is the mechanism on which Java variables work.

KaranJude said...

right said stargazer !!