I am using Visual Studio 2008, and I开发者_JAVA百科 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
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!
You should check the Visual Assist X add-in for Visual Studio. It has lots of features.
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.
Try my AtomineerUtils addin.
It won't do an entire header, but can convert a single method's header declaration into an implementation in the related source file. It adds in the class name/namespaces as required, fills in a default implementation where possible (e.g. return(NULL)) and adds a Doxygen or DocXml doc-comment, incorporating and word-wrapping the comment from the header as the brief description if available.
Are you looking for something to process batches of header files like for building a code generator, or is this a one time thing, whenever you create a new class?
I have a pretty huge selection of self-written Macro's I use during development on a regular basis, and after reading the answers to this question, I'm rather inspired to write a class generator based off of the header file. The best part is, I've already done it, just not in a Visual Studio form. I've done it while writing a code generator, that had to generate all these function calls, and place standard Mutex's around each call, and then also MAKE the default call, and take any error return values, and create a LastError string that was stored in the class.
The bad part is, you can get as crazy as you want with something like this, but it sounds like you'd be happy with basic functionality... I would consider just creating a Macro, that you can create a ToolBar Button for, and if you click it while a header file is loaded, it will rip over it, and (create the .cpp, if it does not exist), scan the .cpp, skipping any methods that might already exist. This would also give you the ability to add new functions to classes and then in one movement generate all the method bodies.
Perhaps you can contact me off SO, and we'll see if our two plans agree. I can see a huge need for this myself... Just FYI; the way I currently handle this...
I construct my .H file, then a copy the entire header over to the .CPP file, and paste it in. Then starts the hackin' and slashin' on the text, getting rid of all the public:, private: protected: lines, the class{} line, and so on.. Then, I copy the classname along with the scope operator to the clipboard, and start going down the screen pasting it in front of all of the methods (functions). Then, do a Search/Replace on ; with "\r\n{\r\n}\r\n"... Plus, whatever other little cleanup I can do...
Using that method, I lose out on a couple of key things. One of them is the above mentioned Doxygen, or other type of comments (If I'm writing API classes, this is FAR more important than if I'm just writing some class for some thing, which I would then put most of the commenting in the FlowerBox, or better yet, write self-commenting code.), and I do not get automagic return values inserted, or even just throw statements that throw some sort of "NotImplemented" exception.
THEN it's time to start writing the class code. :)
As Ed S. mentioned, you are a programmer, so you COULD write this yourself, and if that is your plan, let me know, maybe I can share some of my existing code that might help you out, and we can both benefit from the result.
I hope I am not breaking any SO rules here by posting this answer either, so if I am, I am truly sorry, and I will be glad to remove it, or have an admin remove this post.
Hope this helps, and maybe even gives you some ideas.
精彩评论