The errors generated by the compiler are:
Code:
C:\Users\Josh2\Documents\sandbox\main.cpp||In function 'int main()':|
C:\Users\Josh2\Documents\sandbox\main.cpp|10|error: invalid initialization of reference of type 'std::shared_ptr<T>&' from expression of type 'T*'|
C:\Users\Josh2\Documents\sandbox\main.cpp|5|error: in passing argument 1 of 'void foobar(std::shared_ptr<T>&)'|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===|
However, std::shared_ptr class can construct itself from a raw pointer. You just have to use the constructor. Like this:
Code:
#include <memory>
struct T {};
void foobar(std::shared_ptr<T>& p);
int main()
{
T* my_p = new T;
std::shared_ptr<T> real_p(my_p);
foobar(real_p);
}
This compiles fine for me.