Passing a TStringList by reference/pointer to a function

Viewed 61

I'm rather new at this, but I need to create a TStringList in one function, pass it to another function to modify it, then use the results back in the first function. However, everything I try reports an error:

No matching function call.

Calling function:

std::unique_ptr<TStringList>metaData(new TStringList());
...
_retVal = ParseOMT(inpBuf, &metaData, _reportIt);
...

ParseOMT.h:

bool ParseOMT(const String ABuffer, TStringList* _currMetadata, String &_reportIt);

ParseOMT.cpp

bool ParseOMT(const String ABuffer, TStringList* _metadata, String &_reportIt) {

I have tried various combinations of the * and & in the ParseOMT() declaration and calling function, to no avail.

Can anybody help?

1 Answers

Your ParseOMT() function as shown is fine. The code that is calling it is wrong.

std::unique_ptr has a get() method which returns the object pointer being held.

So, simply change this:

_retVal = ParseOMT(inpBuf, &metaData, _reportIt);

To this instead:

_retVal = ParseOMT(inpBuf, metaData.get(), _reportIt);
Related