从Visual Studio中的标头函数生成代码函数的快速方法? [英] Fast way to generate code functions from header functions in Visual Studio?

查看:179
本文介绍了从Visual Studio中的标头函数生成代码函数的快速方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是个小问题,但是解决方案可以为我节省很多时间并防止出错.

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

我正在Visual Studio中从事C ++项目.如果我在头文件的类中定义函数,请说

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

void InitButton(int ButtonNum);

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

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:

void Button::InitButton() { 
}

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

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 ++ 2010中创建实现

最适合我的解决方案出现在这里: http://www.radwin.org/michael/2011/05/10/stubgen/

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

推荐答案

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

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中的标头函数生成代码函数的快速方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆