CS253

CS253: Software Development with C++

Spring 2018

Dot Vs Pointer

See this page as a slide show

Dot Vs Pointer

CS253 Dot Vs Pointer

Dot or pointer?

Examples

vector<bool> v(42, true);   // v is a vector of bool
cout << v.size() << '\n';
42

Here, we use a dot, because v is an object, not a pointer.

Examples

vector<bool> v(42, true);   // v is a vector of bool
vector<bool> *p = &v;       // p is a pointer to vector of bool

cout << (*p).size() << ' '
     << p->size()   << '\n';
42 42

Two ways (one ugly, one not) of doing the same thing.

Examples

vector<bool> v(42, true);   // v is a vector of bool
vector<bool> &r = v;        // r is a reference to a vector of bool
cout << r.size() << '\n';
42

Modified: 2018-01-07T11:29

User: Guest

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building