D
Damon
Hi,
Can someone point out to me what's wrong with the code below? I'm
trying to reuse the deleted pointer but it won't compile. My reason
may be wrong, but I thought reusing the pointer would save the trouble
of declaring a pointer to a string array.
I also suspect there will be a problem of releasing memory in the way
I'm using the array pointer and is toying with using a
vector<std::string> instead. Anyway, thanks for any pointers give.
--------------snip---------------------
std::map<int, std::string*> notes;
std::string *bi_val = new std::string[2];
bi_val[0] = "W";
bi_val[1] = "E";
notes.insert( std:air<int,std::string*>( 4, bi_val ) );
bi_val = new std:string[2]; // error here
bi_val[0] = "S";
bi_val[1] = "N";
notes.insert( std:air<int,std::string*>( 2, bi_val ) );
bi_val = new std:string[2]; // same error here
bi_val[0] = "SE";
bi_val[1] = "NW";
notes.insert( std:air<int,std::string*>( -2, bi_val ) );
bi_val = new std:string[2]; // error!
bi_val[0] = "SW";
bi_val[1] = "NE";
notes.insert( std:air<int,std::string*>( 6, bi_val ) );
Can someone point out to me what's wrong with the code below? I'm
trying to reuse the deleted pointer but it won't compile. My reason
may be wrong, but I thought reusing the pointer would save the trouble
of declaring a pointer to a string array.
I also suspect there will be a problem of releasing memory in the way
I'm using the array pointer and is toying with using a
vector<std::string> instead. Anyway, thanks for any pointers give.
--------------snip---------------------
std::map<int, std::string*> notes;
std::string *bi_val = new std::string[2];
bi_val[0] = "W";
bi_val[1] = "E";
notes.insert( std:air<int,std::string*>( 4, bi_val ) );
bi_val = new std:string[2]; // error here
bi_val[0] = "S";
bi_val[1] = "N";
notes.insert( std:air<int,std::string*>( 2, bi_val ) );
bi_val = new std:string[2]; // same error here
bi_val[0] = "SE";
bi_val[1] = "NW";
notes.insert( std:air<int,std::string*>( -2, bi_val ) );
bi_val = new std:string[2]; // error!
bi_val[0] = "SW";
bi_val[1] = "NE";
notes.insert( std:air<int,std::string*>( 6, bi_val ) );