Is there a way to accomplish what this block of code does in C++ without using a typedef?
typedef int* pointer;
int a = 3;
int* ap = &a;
const pointer& apr = ap;
*apr = 4;
This won't do it:
int b = 3;
int* bp = &b;
const int*& bpr = bp;
*bpr = 4;
In fact, that second block won't compile, because the const
makes bpr a reference to a read-only pointer, not a const reference to a read-write pointer. I was kinda hoping that parenthesis would save me:
const (int*)& bpr = bp;
...but no luck there. So do I have to typedef the pointer type in order create a const reference to a read-write pointer?