Board index » cppbuilder » Access violation with 'new[]'
ta0kira
![]() CBuilder Developer |
Access violation with 'new[]'2004-01-20 05:23:30 PM cppbuilder31 I have an area of my code that calls 'new[]' which works fine, except in certain situations I get an access violation. I would post the code, however I don't think the use of 'new[]' itself is the problem. This occurs in a class function, and I think it might be being called against a bad pointer, but I am not sure. Can anyone tell me what kind of thing I should look for to find the problem (I am already looking for bad casts)? I have inserted 'std::cout' with test output to try to trace it back to the source (by looking at the last output line before the violation to see what called the function) as follows: struct A { void F1() { std::cout << "F1 Start\n"; //Do stuff std::cout << "F1 End\n"; } }; struct B { void F2() { std::cout << "F2 Start\n"; DATA.F1(); //Do stuff std::cout << "F2 End\n"; } private: A DATA; }; int main() { B ONE; std::cout << "1\n"; ONE.F2(); std::cout << "2\n"; B *TWO = &ONE; std::cout << "3\n"; TWO->F2(); std::cout << "4\n"; } however the source is not consistent, and can be effected by adding code to a completely unrelated area (such as adding a 'std::cin.get()' in main()). Something that has been happening also (that might be related): when I use 'std::cin.get()', sometimes I will press enter too quickly, and then the entire program will scroll past any further input all the way to the end. Sometimes this ends in an access violation. Any help is greatly appreciated. Thanks ta0kira |