I have a problem with a class function which deletes and re-creates some members within the class (C_mystring* name and C_mystring* designation); these are just pointers to instances of my own string class (a char* and an int for the length); However, once the function exits, the values of the pointers seem to be changed as I have debugging code which prints out the addresses of the pointers as the function exits, and again after it exits. (For each one, name and designation, the pointer values are 240 greater after exitting the function.) Partial code shown (debugging code is at end of CreateUnitFromFile and at end of main both shown below):
-------------------------------------------
C_unit::CreateUnitFromFile(C_mystring* inputfilename)
delete designation;
delete name;
// ******* More?
C_mystring* filedata = new C_mystring; // string to hold file data
filedata = ReadTextFile(inputfilename->Getstring()); // Get file data
C_mystring* tempstring = new C_mystring; // temporary string to hold
// parts of file data
tempstring->CreateString(filedata->Getstring()); // copy file data to temp string
C_mystring* designation = new C_mystring;
C_mystring* name = new C_mystring;
designation->CreateString(tempstring->Search_and_Pick_Line("Designation:"); //Get designation
tempstring->CreateString(filedata->Getstring()); // copy file data to temp string
name->CreateString(tempstring->Search_and_Pick_Line("Name:"); // Get name
delete tempstring; // free memory of temporary strings
delete filedata; // free memory of temporary strings
//DEBUG
printf("\nname is: "
printf(name->Getstring());
printf("length of name string: %i \n", name->Getlength());
printf("\ndesignation is: "
printf(designation->Getstring());
printf("length of designation string: %i \n", designation->Getlength());
printf("address of name object is: "
printf("%i \n", name);
printf("address of designation object is: "
printf("%i \n", designation);
}
----------------------------------------------
(within main program which calls this function)
C_mystring* filepath = new C_mystring;
filepath->CreateString("c:\\Game Development\\Unit Data\\Generic Tank.txt"
C_unit* testunit = new C_unit;
testunit->CreateUnitFromFile(filepath);
printf("address of name object is: "
printf("%i \n", testunit->name); //Here the value is 240 greater
printf("address of designation object is: "
printf("%i \n", testunit->designation); //Here the value is 240 greater
------------------------------
and ideas greatly appreciated!
-------------------------------------------
C_unit::CreateUnitFromFile(C_mystring* inputfilename)
delete designation;
delete name;
// ******* More?
C_mystring* filedata = new C_mystring; // string to hold file data
filedata = ReadTextFile(inputfilename->Getstring()); // Get file data
C_mystring* tempstring = new C_mystring; // temporary string to hold
// parts of file data
tempstring->CreateString(filedata->Getstring()); // copy file data to temp string
C_mystring* designation = new C_mystring;
C_mystring* name = new C_mystring;
designation->CreateString(tempstring->Search_and_Pick_Line("Designation:"); //Get designation
tempstring->CreateString(filedata->Getstring()); // copy file data to temp string
name->CreateString(tempstring->Search_and_Pick_Line("Name:"); // Get name
delete tempstring; // free memory of temporary strings
delete filedata; // free memory of temporary strings
//DEBUG
printf("\nname is: "
printf(name->Getstring());
printf("length of name string: %i \n", name->Getlength());
printf("\ndesignation is: "
printf(designation->Getstring());
printf("length of designation string: %i \n", designation->Getlength());
printf("address of name object is: "
printf("%i \n", name);
printf("address of designation object is: "
printf("%i \n", designation);
}
----------------------------------------------
(within main program which calls this function)
C_mystring* filepath = new C_mystring;
filepath->CreateString("c:\\Game Development\\Unit Data\\Generic Tank.txt"
C_unit* testunit = new C_unit;
testunit->CreateUnitFromFile(filepath);
printf("address of name object is: "
printf("%i \n", testunit->name); //Here the value is 240 greater
printf("address of designation object is: "
printf("%i \n", testunit->designation); //Here the value is 240 greater
------------------------------
and ideas greatly appreciated!