Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assinging dynamically allocated CStrings 2 1

Status
Not open for further replies.

reneb

Programmer
Aug 8, 2000
43
US
I don't know if you read my previous question because it strongly relates to this one. I have dynamically created a structure of type SiteStruecture using this time malloc instead of calloc.
struct SiteStructure
{
int numOfSect;
double easting;
double northing;
CString siteCodeStr;
CString prdPath[6];
CString prdNames[6];
double eIRP[6];
int angle[6];
SiteStructure * nextSite;
}

when I try to assign values to the siteCodeStr, which is a CString I get a memory access violation error, When I try to assing the doubles or ints, I have no problem. Does any one have a clue as to what is going on? Desparate, please help. Thanks in advance.

[sig][/sig]
 
Dear reneb,

malloc, calloc and such do not 'construct' objects, they just allocate memory. Use the 'new' operator to construct your structure and the CString constructors will be called.

struct SiteStructure* pSStruct = new SiteStructure;
pSStruct->siteCodeStr = "hello CString";
cout << (LPCSTR)pSStruct->siteCodeStr << endl;

Hope this helps
-pete [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top