[Cs3] arrays and pointer arithmentic with unique_ptr

Mikhail Nesterenko mikhail at cs.kent.edu
Thu Nov 21 15:52:37 EST 2019


CS3 students,

pointer arithmetic is not allowed for unique_ptr. However, indexing is
allowed. The indexing is restricted for the case where the pointer
manages an array. In this case it has to be declared as such:

   std::unique_ptr<int[]> a(new int[5]);   

I added an example that demonstrates this feature here:

   http://vega.cs.kent.edu/~mikhail/classes/cs3/Examples/SmartPointers/uniqueArray.cpp

Thanks,
-- 
Mikhail


More information about the cs3 mailing list