Alf P. Steinbach <al***@start.nowrote:
auto_ptr calls delete, whereas you need delete[]. Not that it matters
much in practice for a char array. But formally UB.
When the function returns, the auto_ptr calls delete. As mentioned
Try what I posted earlier, it's safe:
i got it, 10x
but i'm afraid that the vector isn't equiv to the array of poiter to chars
may be this is a better way?
//--code--
class constchar
{
private:
const char** v;
public:
constchar (const std::vector<std::string>& arg_);
inline virtual ~constchar () { delete [] v; }
inline operator const char** () const { return v; }
}; //!class constchar
//
constchar::constchar (const std::vector<std::string>& arg_)
{
v = new const char* [arg_.size()+1];
std::vector<std::string>::const_iterator i = arg_.begin();
size_t j;
for (j^=j; i != arg_.end (); ++i)
{
v[j++] = (*i).c_str() ;
}
v[j] = NULL;
}
int
main ()
//////.......
vector<stringargv;
vector<stringenvp;
....
::execve (..., constchar (argv), constchar (envp));
::spawnve (..., constchar (argv), constchar (envp));
//--code--
--
www.andr.ca