dPo*_*Pol 4 c++ pass-by-pointer
我想调用一个库的函数(我无法修改)
void function(int* i, char* c);
Run Code Online (Sandbox Code Playgroud)
有没有办法调用函数定义int和动态char?
即做某事
function(&1, &'v');
Run Code Online (Sandbox Code Playgroud)
代替
int int_1 = 1;
char char_1 = 'v';
function(&int_1, &char_v);
Run Code Online (Sandbox Code Playgroud)
这将极大地减少我的代码长度,同时提高可读性.
正如其他人所说,答案是否定的......
您可以通过重载来模拟它function:
void function(int i, char c)
{
function(&i, &c);
}
Run Code Online (Sandbox Code Playgroud)
所以现在你可以写 function(1, 'v')