CS253: Software Development with C++

Spring 2018

Dot Vs Pointer

See this page as a slide show

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

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2018-04-24T16:51

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building