Freeing memory with Pointer Arithmetic
Posted
by
Breedly
on Stack Overflow
See other posts from Stack Overflow
or by Breedly
Published on 2012-08-29T21:30:27Z
Indexed on
2012/08/29
21:38 UTC
Read the original article
Hit count: 175
c++
C++ newb here. I'm trying to write my own implementation of an array using only pointers, and I've hit a wall I don't know how to get over.
My constructor throws this error
array.cpp:40:35: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
When my array initializes I want it to free up all the spaces in the array for ints.
Array::Array(int theSize){
size = theSize;
int *arrayPointer = new int;
int index = 0;
while(theSize > index){
*(arrayPointer + index) = new int; //This is the trouble line.
++index;
}
}
What am I doing wrong stackoverflow?
© Stack Overflow or respective owner