D
DaKoadMunky
Can you provide a working example with a main() using such a function
A library function I developed dynamically allocated data which it then passed
to a callback. The callback had the option of assuming ownership of that
dynamically allocated data. The callback had an argument of type reference to
pointer to type T. If the callback wanted to assume ownership of the
dynamically allocated data it could do so by copying the referenced pointer and
then setting the referenced pointer to zero. The library would then attempt to
delete a null pointer, which of course is a safe operation. If the callback
did not want to assume ownership of the dynamically allocated data then it did
not modify the referenced pointer. In that case the library deleted the
dynamically allocated data.
typedef void (*DataUser)(char*&);
void DataCreator(DataUser dataUser)
{
char *data = new char(0);
dataUser(data);
delete data;
}
void DataUser1(char*& data)
{
//Make copy of data for later usage and deletion
data = 0;
}
void DataUser2(char*&)
{
}
int main()
{
DataCreator(DataUser1);
DataCreator(DataUser2);
return 0;
}
Brian F. Seaberg
Naperville, Illinois
Delray Beach, Florida
accepting char * &?
A library function I developed dynamically allocated data which it then passed
to a callback. The callback had the option of assuming ownership of that
dynamically allocated data. The callback had an argument of type reference to
pointer to type T. If the callback wanted to assume ownership of the
dynamically allocated data it could do so by copying the referenced pointer and
then setting the referenced pointer to zero. The library would then attempt to
delete a null pointer, which of course is a safe operation. If the callback
did not want to assume ownership of the dynamically allocated data then it did
not modify the referenced pointer. In that case the library deleted the
dynamically allocated data.
typedef void (*DataUser)(char*&);
void DataCreator(DataUser dataUser)
{
char *data = new char(0);
dataUser(data);
delete data;
}
void DataUser1(char*& data)
{
//Make copy of data for later usage and deletion
data = 0;
}
void DataUser2(char*&)
{
}
int main()
{
DataCreator(DataUser1);
DataCreator(DataUser2);
return 0;
}
Brian F. Seaberg
Naperville, Illinois
Delray Beach, Florida