/// <summary>
/// 结构体
/// </summary>
struct MyStruct
{
int a=100;
string str="";
};
/// <summary>
/// 用来测试的函数
/// </summary>
/// <param name="a"></param>
/// <param name="str"></param>
/// <param name="out"></param>
void test(int a, string str, void* out) {
MyStruct* result = (MyStruct*)out;//首先赋值了一个有实际类型的指针
result->a = a;
result->str = "10000";
}
int main() {
MyStruct* mystruct=new MyStruct();
mystruct->a = 1000;
mystruct->str = "shd";
auto s = new MyStruct();
test(983, "",s);
cout << s->a << " " << s->str << endl;
}
如何传入万能指针void以及使用简单示例
最新推荐文章于 2023-09-03 10:41:20 发布