Access Violation with uninitialized variable being passed to method call that initializes it

I need some theoretical explanation of the following memory access violation BEFORE even entering the method:

String testMethod (AnsiString param1);
AnsiString A1 = testMethod(A1);

I am trying to understand the theory behind the problem.

A1 is getting initialized by the return value of testMethod() while at the same time it is passed to testMethod(). What happens before the method is actually entered? When passed to testMethod() it has no actual value/a random value, has it? A local copy of A1 is created, does the exception occur during that process, actually?

Trying to debug, a lot of AnsiString, UnicodeString, and AnsiStringBase methods are entered.

Why does it work, when I change the method signature this way:

AnsiString testMethod (AnsiString param1);

Source: Windows Questions C++

LEAVE A COMMENT