Lit*_*ton 2 c++ com smart-pointers
使用CComPtr或_com_ptr智能指针作为输入输出参数的最佳方法是什么?
void FunctionPrototype(Test** test) {
// you can use here test or create a new Test here and assign to test
}
CComPtr<Test> test;
test.CoCreateInstance(..., ..., ...);
test->SetValue(10);
FunctionPrototype(&test); // assertion since test.p is not NULL
Run Code Online (Sandbox Code Playgroud)
定义旁边有一条评论CComPtr<T>::operator&:
断言操作符&通常表示错误.但是,如果这确实是需要的,请明确地获取p成员的地址.
所以请使用调用您的函数
FunctionPrototype(&test.p);
Run Code Online (Sandbox Code Playgroud)