Mohsen67
Mohsen67

Reputation: 135

pass smart pointers as a pointer of pointer to a function

I'm trying to pass a smart pointer as a parameter of a function which takes a pointer of a pointer. I was wondering if there is any proper solution for that.

foo(Class** input)
{
   // Do something
}

myClass = std::make_Unique<Class>();

foo(&myClass.get())

Upvotes: 0

Views: 118

Answers (1)

MSalters
MSalters

Reputation: 180303

That won't work, and it's a good thing that it doesn't.

There are roughly two reasons why you need to pass a Foo**. It could be a function that wants a 2D array (array of pointers to arrays), or the function has a Foo*as output (should have used a Foo*& then). In your case, it appears that you're dealing with the array case, since the argument is called input.

Upvotes: 2

Related Questions