这是通过引用传递文件指针的正确语法吗?
函数调用:printNew(&fpt);
printNew(FILE **fpt)
{
//change to fpt in here kept after function exits?
}
最佳答案
没有。正确的语法是
void printNew(FILE *&fpt)
{
//change to fpt in here kept after function exits?
}
您的代码只会将本地指针更改为 FILE 指针。代码中的调用者只能看到对 *fpt
的更改。如果将其更改为上面的内容,则将通过引用传递内容,并按预期促进更改。相应的参数照常传递
printNew(fpt);
关于c++ - 这是通过引用传递文件指针的正确语法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3230995/