Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating .cpp files from .h files visual studio

I am using Visual Studio 2008, and I was wondering if it was possible to create the .cpp files given the header files.

So if I have a .h files with a class and functions, it can create the code file with all the functions typed in with a blank body

like image 637
Jamie Avatar asked Oct 22 '09 21:10

Jamie


People also ask

How do I create a header file for cpp in Visual Studio?

To create a header file for a new class, right-click to open the shortcut menu for the MathLibrary project in Solution Explorer, and then choose Add > New Item. In the Add New Item dialog box, select Visual C++ > Code. In the center pane, select Header File (. h).

What is the difference between .cpp and .h files?

. h files, or header files, are used to list the publicly accessible instance variables and methods in the class declaration. .cpp files, or implementation files, are used to actually implement those methods and use those instance variables.

Does every .h file need a .cpp file?

Cpp files don't always have to have a header file associated with it but it usually does as the header file acts like a bridge between cpp files so each cpp file can use code from another cpp file. One thing that should be strongly enforced is the no use of code within a header file!


3 Answers

Shortcut: alt+shift+f10 (VS2015)

I've looked for this for over 10+ years, been told numerous times that nothing like this exists, and that one needs to somehow use external tools to get this basic functionality.

... Now, I've finally found something useful.

Highlight the class name in you .h file, and using that shortcut will make intellisense generate the relevant definitions (also creating the .cpp file if not created).

It's also a general purpose shortcut that ex. creates method stubs for you, if you create function signatures in the header (and highlight the function name). As you can see from the screenshot below, it also allows you to auto create all virtuals from the parent class, etc.

I absolutely cannot believe how much this has suddenly improved productivity (goodbye manual copy paste!). And I find it utterly shocking how I have never seen / been given reference to this, even in Stack Overflow, up until this point.

Enjoy your new powers, and spread the word!

Revolution

like image 124
dk123 Avatar answered Sep 24 '22 23:09

dk123


You should check the Visual Assist X add-in for Visual Studio. It has lots of features.

like image 23
Semih Yagcioglu Avatar answered Sep 24 '22 23:09

Semih Yagcioglu


You can say Project -> Add Class but that only does the basics. I don't think you can do (yet) what you are suggesting but it would be really awesome and there is no reason (that I can think of) why you cannot.

like image 45
Robert Massaioli Avatar answered Sep 25 '22 23:09

Robert Massaioli