Implementing an automatic C ++ class in the editor

Much of my time spent developing applications in C ++ was wasted on implementing class definitions. By this I mean prototyping classes, and then creating their respective implementations.

For example:

#ifndef FOO_H #define FOO_H class Foo { public: Foo (const X& x, const Y& Y); ~Foo (); void PerformXYZ (int Count); }; #endif 

And now I have to copy and paste, and then add the repeating Foo :: to each function.

 Foo::Foo (const X& x, const Y& Y) { } Foo::~Foo () { } void Foo::PerformXYZ (int Count) { } 

Now I copy the function declarations to the corresponding * .cpp files, deleting the blank lines, and then replacing the ';' with "\ n {\ n \ n} \ n". However, I still have to specify a namespace for each function.

Are there tools in Eclipse, Vim, or any other IDE / editor tool that take this load from the developer?

+6
c ++ editor
source share
6 answers

Visual Studio has tools for adding functions and variables. Tools automate this process. But I never use them :)

Visual Assist X has a feature that helps add an implementation for methods. This is the best solution.

+5
source share

In Visual Studio 2008, you can add a class (it will generate .h and .cpp files for you) using the option Project-> Add Class .... But it is very primitive and only writes constructor and destructors. After adding a class, you can go to the class view and use the "Add Method" option to add methods to the class.

+2
source share

Like you, I have long thought that the time when a C ++ developer is wasted writing tedious class definitions. The only tool I have found so far that partially eliminates this work is VisualAssistX, as one of the other posters mentions.

Although it completely eliminates the need to write class definitions, VA X has some good refactoring methods that help in this area. For example, you can create a method declaration, and it will automatically create an implementation body for you. You can also do things like “Add a similar element”, which fills the “add element” dialog box with the data of an existing method or changes the signature of a function and automatically distributes it to both cpp and h files.

It is not free, but costs money.

Jeroen

+2
source share

For vim, I support this package , which provides class fragments (which can be easily adapted to your needs).

NB: the generation of each function definition can be automated with the command :GOTOIMPL , but it must be executed after the function after the function.

+1
source share

Eclipse probably has something to do with this refactoring menu, although I have not used it for a year and I don’t remember any features.

+1
source share

The Zeus editor can be customized this way using its template function as follows.

Step 1: Create a file c: \ temp \ test.tpl that looks like this:

 #ifndef $Word_H #define $Word_H class $Word { public: $Word (const X& x, const Y& Y); ~$Word (); void PerformXYZ (int Count); }; #endif $Word::$Word (const X& x, const Y& Y) { } $Word::~$Word () { } void $Word::PerformXYZ (int Count) { } 

Step 2: Using the template, the Options menu to add the following template:

 $ExpandTemplate<c:\temp\test.tpl> 

Step 3: Using the menu "File", "New", enter the word "Bar", place the cursor on the word "Bar" and run the newly created template, and you will get this text:

 #ifndef Bar_H #define Bar_H class Bar { public: Bar (const X& x, const Y& Y); ~Bar (); void PerformXYZ (int Count); }; #endif Bar::Bar (const X& x, const Y& Y) { } Bar::~Bar () { } void Bar::PerformXYZ (int Count) { } 
0
source share

All Articles