C++ basic
11 May 2014
const pointer //you can't change it to point to somewhere else
int * const cpI;
const int* cpI //you can't use it to change the value of the target
shared_ptr
#include <memory>
std::shared_ptr<Resource> pResource; //declare a shared_ptr
// use std::make_shared to initialize Resource instance
pResource = std::make_shared<Resource>(firstname);
auto sharedPointer = std::make_shared<Person>("Sean", "xu");
References
the &
before variable is to get the address of that variable eg:
int i = 10;
int* pint = &i; // which means pint is a point to i
*pint = 12; // change the value that pint point to in this case the value of i will be changed to 12
int& j = i;
j = 12;
Tweeter localT("Twetter",123,"@local");
Person& localp = localT;
localp.GetName();
what’s the difference between reference and pointer?
blog comments powered by Disqus