samedi 5 octobre 2019

How to move to the next pointer in a smart pointer array

I've been trying to figure out how Smart Pointer arrays work with a test program meant to read in a file one char at a time, and store each char at a pointer in said array. However, I have been having trouble increasing the pointer in order to set later variables of the array. While without smart pointers, I could simply type out, for example,

char *check = new char[length];
for (int i =0; i < length; i++);{
    *check=='a';
    check++;
}

and it would allow me to assign a value to each pointer in the pointer array, doing the same with a smart pointer array results in the following error upon the line of the 'check++',

//This is the smart pointer I've been using, for reference;
std::shared_ptr<char> right(new char(length));
error: no 'operator++(int)' declared for postfix '++' [-fpermissive]

For a moment, let's forget that bracket notation doesn't exist (it works, but I want to know a way to do this in pointer notation), so I can increase or access future pointers in a reliable manner such that I can use it in things like loops to input values in each pointer of a smart pointer array.

Aucun commentaire:

Enregistrer un commentaire