C++ 从 Visual Studio 中的头函数生成代码函数的快速方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17961648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 21:37:05  来源:igfitidea点击:

Fast way to generate code functions from header functions in Visual Studio?

c++visual-studio

提问by escapecharacter

This may be a minor question, but a solution would save me a lot of time and prevent mistakes.

这可能是一个小问题,但一个解决方案会为我节省大量时间并防止错误。

I am working on a C++ project in Visual Studio. If I define a function in a class in a header file, say

我正在 Visual Studio 中处理 C++ 项目。如果我在头文件的类中定义一个函数,请说

void InitButton(int ButtonNum);

I usually copy and paste the signature to the cpp file. Then, I insert the class name, and replace the semi-colon with curly braces, like so:

我通常将签名复制并粘贴到 cpp 文件中。然后,我插入类名,并用花括号替换分号,如下所示:

void Button::InitButton() { 
}

However, I'll often forget the class name, or accidentally type it before the return type. This also happens for any static variables I need to define in code. This seems small, but piles up since I'm at the beginning phase of a project. Is there a quicker way to auto-generate these in Visual Studio C++? Or a best practice I'm missing out on?

但是,我经常会忘记类名,或者不小心在返回类型之前键入它。这也适用于我需要在代码中定义的任何静态变量。这看起来很小,但由于我处于项目的开始阶段,因此堆积如山。有没有更快的方法在 Visual Studio C++ 中自动生成这些?还是我错过的最佳实践?

EDIT: It appears this has been asked before: Auto-create implementation in Visual Studio C++ 2010

编辑:之前似乎有人问过这个问题:Auto-create implementation in Visual Studio C++ 2010

EDIT 2: The best solution for me appears here: http://www.radwin.org/michael/2011/05/10/stubgen/

编辑 2:对我来说最好的解决方案出现在这里:http: //www.radwin.org/michael/2011/05/10/stubgen/

回答by mrbraitwistle

In Visual Studio 2015 there's the "Quick Actions" feature, a light bulb that shows up whenever you hover over a piece of code. In a header file one of the options is "Create definition of ... in ....cpp". This option generates the function definition in the corresponding header file.

在 Visual Studio 2015 中有“快速操作”功能,当您将鼠标悬停在一段代码上时,就会出现一个灯泡。在头文件中,选项之一是“在 ....cpp 中创建 ... 的定义”。此选项在相应的头文件中生成函数定义。

回答by Dominique McDonnell

Visual Assisthas a generator for this. I'm sure there are a lot of plugins that have the same functionality, but you might have to part with some cash for them. Visual Assist is well worth the money though, as it gives you a lot of functionality which I find invaluable. My killer features are the better function and method info, better auto complete and find file in projects (one key combination and you get a list of all files in all projects and can search for a particular file without knowing where in the hierarchy it lives).

Visual Assist有一个生成器。我敢肯定有很多插件具有相同的功能,但您可能需要为它们支付一些现金。不过,Visual Assist 物有所值,因为它为您提供了许多我认为无价的功能。我的杀手锏是更好的函数和方法信息,更好的自动完成和在项目中查找文件(一个组合键,您可以获得所有项目中所有文件的列表,并且可以在不知道它在层次结构中的位置的情况下搜索特定文件) .