简体   繁体   English

C ++:有没有办法通过更改长声明来避免冗余?

[英]C++: Is there a way to avoid redundancy with changing long declarations?

This has always bugged me with C and C++: 这总是让我误以为C和C ++:

In my header file I have something like: 在我的头文件中,我有类似的东西:

bool UpdateWindow( int w, int h, char bpp, bool force, char* someOtherLongStuff )

Now, if I want to change that for whatever reason, I have to do so in both header and source file - that's annoying in my opinion. 现在,如果我想因任何原因改变它,我必须在头文件和源文件中这样做 - 这在我看来很烦人。

Is there a way to automate this? 有没有办法实现自动化?

I'm using Visual Studio 2010 我正在使用Visual Studio 2010

I don't know of a shortcut for this, but even if one exists it might not give you as much of a saving as you imagine. 我不知道这个的捷径,但即使存在,它可能也不会像你想象的那样给你带来拯救。 If you are changing the header file then there are probably a lot of other places that will be affected by the change (the method body, other application code that includes this header, your client's code if you ship it as a library, unit tests, etc.) so having to change it in two places is just the tip of the iceberg. 如果您要更改头文件,那么可能还有很多其他地方会受到更改的影响(方法体,包含此标题的其他应用程序代码,客户端代码,如果您将其作为库发送,单元测试,所以不得不在两个地方改变它只是冰山一角。

I think I got it running with Visual Assist from Wholetomato. 我想我是用Wholetomato的Visual Assist运行的。 It's commercial but you could give it a try... 这是商业广告,但你可以尝试一下......

C++ was a long time ago - at least for me :) C ++很久以前 - 至少对我来说:)

Not with the standard visual studio. 不是标准的视觉工作室。 I think you need a refactoring tool like Resharper, but I am not sure it will work for C++. 我认为你需要像Resharper这样的重构工具,但我不确定它是否适用于C ++。 Refactoring for C++ is a very though problem. 重构C ++是一个非常棘手的问题。 My best shot would be to just follow the declaration with ctrl+click on the name and change in both sides. 我最好的方法就是按照ctrl点击声明并点击名称并在两侧进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM