With my friend we made a program with overriden new and new[] operators. I discovered that when I try to create string array with this code:
string* Test1 = new string[10];
Function returns invalid pointer (Usually it's value is moved 8 bits foreward, I'm compilling program to x64 platform). Our new[] function looks like that:
void* operator new[] (size_t e)
{
void* Test2 = operator new(e);
return Test2;
}
when running program with debugger before return, pointer Test2
had value 0x0000000009dfaa90, but value of Test1
became 0x0000000009dfaa98.
This situation happens only with string type. I've tried do the same with "int[10]", "string* [10]" and object of one of my classes but problem occures only when dealing with string, also, code:
string* Test1 = new string;
works perfectly fine.
Could someone explain me why it's happenning and how to make it works correctly?
PS: We are using Visual Studio 2012 Proffesional
Edit: I just tested it non-overriden new[]
and it's working this same way when creating string table (Returned pointer is other than the one that function try to return
), so it seems to not be a problem. Could someone explain me why value of pointer changes only for string arrays, and how it changes if there seems to not be any other instruction that could change it?