I am learning/relearning C/C++. I have created a template class with various working functions. I have a problem when I try to use code that works for a char datatype with an AnsiString.
If I call a template class function by calling a template function and passing a variable "Data" that I have created as an AnsiString, but not set equal to any value as of the time that it is passed, I find that if I try to set "Data" equal to any string in the template class function that is called, I can assign a value to "Data" in the template class function and display it, but can not access the string I stored in "Data" in the template class function when control is returned to the code block in which I called the template class function.
This is not a problem if I use a similar call to a template function in the class I have defined using a char. In fact, if I call the template function and pass Data as an AnsiString, I can assign a value to "Data.strcpy()" and without returning that value access "Data.strcpy()" in the block in which I call the template class function (of course, only after the function is called).
I need to be able to change the value of an AnsiString variable "Data" in a template class function, then access the same AnsiString variable "Data" in the calling code block immediately after the function call. I do not want to use the "Data.strcpy()" method to access it after I call the function by setting "Data.strcpy()" equal to the string I want returned in the template class function, then setting an AnsiString "Data" equal to "Data.strcpy()", which will work, but is awkward and introduces an inconsistency.
In part, I don't understand why I can change the string stored in a char variable in a template class function after calling it, then access the char, but can not do the same thing with an AnsiString variable.
I did read that the 4 byte long AnsiString variable maintains a counter that changes when the variable value is changed, and that the same address can be associated with two different AnsiStrings. I believe that the compiler is treating the "Data" variable references, when they are defined as an AnsiString, as two different variables, one associated with the calling code block, and the other with the template class function. The char references are pointers, and do not change when sent to the template class.
I would like to know how to send an AnsiString variable called "Data" to a template class function so that the calling block can immediately access the value associated with the AnsiString variable "Data" that is assigned to it in the template function after control is returned to the line in the calling block of code after the function is called. I believe I need to find a way to make the "Data" AnsiString variable in the calling block the same one that is sent to and into which a string is loaded by the template class function. This should enable me to access the string stored in "Data" by the template class function in the calling block.
Thank you in advance for any help that you can provide into dealing with this problem. I'm sure that it is trivial for an experienced C++ programmer.