Hey guys,
SO...I was feeling confident in my understanding of the various uses of const with pointer declarations to restrict how they function...I was doing fine until I came across a bit of code that I modified thinking that a const pointer to const would do fine...tell me what I'm missing here...here's the full code minus the preprocessor directives and I'm using the std namespace:
Ok...so...the const pointer to const was my addition and the logic behind it is I just don't see any change to the value of the element in the function...so why do I get a compile error? Any insight would be very very helpful...even looking over it now, all I'm doing is accessing a value...I'm not altering it...anyways, any help would be great. Thanks, ChapCode://returns a pointer to a string element string * ptrToElement(const vector<string> * const pVec, int element); int main() { vector<string> inventory; inventory.push_back("sword"); inventory.push_back("shield"); cout << "Sending the object pointed to by a return pointer:\n"; cout << *(ptrToElement(&inventory, 1)) << endl; return 0; } string * ptrToElement(const vector<string> * const pVec, int i) { return &((*pVec)[i]); }