gpt4 book ai didi

c++ - 更改对已弃用方法的引用 C++

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:08:03 25 4
gpt4 key购买 nike

我的代码库中有一些方法已弃用,我知道我应该如何替换它们,有什么方法可以自动执行此操作吗?我正在使用 Visual Studio 2015 update 3,但我愿意使用其他文本编辑器...

代码如下所示:

// Deprecated method
myFunction(char* firstParam, char* secondParam = NULL);

// New method, same name, different params
myFunction(char* firstParam, bool flag, char* secondParam = NULL);

我只想要一些可以用对第二个函数的引用替换对第一个函数的所有引用的东西。即:

myFunction( "hello", "world");
// Replace with
myFunction( "hello", true, "world");

myFunction("hello");
// Replace with
myFunction("hello", true);

myFunction("hello", isTrue); // isTrue is a bool here
// Do not replace with anything

myFunction("hello", world); //world is a char* here
// Replace with
myFunction("hello", true, world);

我对使用 visual studio 甚至其他文本编辑器的解决方案持开放态度。我没有手动执行的原因是代码库太大。

最佳答案

更改旧函数以在该参数为真时调用新函数(当然是在旧函数之上声明新函数):

 // Deprecated method
myFunction(char* firstParam, char* secondParam = NULL)
{
myFunction(firstParam, true, secondParam);
}

你也可以内联它,这样编译器就会在适当的时候为你更改代码:)

关于c++ - 更改对已弃用方法的引用 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46566616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com