oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Jul 04, 2008 8:46 pm Post subject: deallocation errors |
|
|
I'm zoning in on a method to deallocate the last element of an array's memory (in result, deleting it from the array). This is what I have. It doesn't actually deallocate the memory but it does the job. Just I'm getting these stupid errors that I can't figure out how to fix x_x Here's my code
| Code: |
void DeleteArrayIndex(int index) {
if(index < count) {
memmove(&array[index], &array[index+1], ((count-1)-index)*sizeof(int));
int *temp = (int*)calloc(count-1, sizeof(int));
int *temp2 = array;
&array = temp;
memcpy(array, temp2, (SIZE_T)temp);
count--;
}
else if(index == count) {
int *temp = (int*)calloc(count-1, sizeof(int));
int *temp2 = array;
&array = (int[count])temp;
memcpy(array, temp2, (SIZE_T)temp);
}
}
|
Here are my errors.
| VC++ wrote: |
------ Build started: Project: test, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\users\OIB\documents\visual studio 2008\projects\test\test\main.cpp(16) : error C2440: '=' : cannot convert from 'int *' to 'int (*)[10]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\OIB\documents\visual studio 2008\projects\test\test\main.cpp(23) : error C2540: non-constant expression as array bound
c:\users\OIB\documents\visual studio 2008\projects\test\test\main.cpp(23) : error C2440: 'type cast' : cannot convert from 'int *' to 'int [1]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
Build log was saved at "file://c:\Users\OIB\Documents\Visual Studio 2008\Projects\test\test\Debug\BuildLog.htm"
test - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|