tags:

views:

276

answers:

6

Much of my time spent developing C++ applications is wasted implementing class definitions. By that I mean the prototyping of classes 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'll have to copy and paste, then add the repetitive Foo:: onto each function.

Foo::Foo (const X& x, const Y& Y)
{

}

Foo::~Foo ()
{

}

void Foo::PerformXYZ (int Count)
{

}

For now I copy the function declarations over to their respective *.cpp files, remove empty lines, then replace ';' with "\n{\n\n}\n". However, I still have to specify the namespace for each function.

Are there tools in Eclipse, Vim or any other IDE/editor that take this burden off a developer?

+1  A: 

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

Naveen
+5  A: 

In Visual Studio there are tools to add functions and variable. Tools automates the process in question. But I never use them :)

In the Visual Assist X there is the feature that helps to add implementation for methods. It is the best solution.

Kirill V. Lyadvinsky
+1 Visual Assist.
peterchen
I, too, find these GUI helpers of limited use as I can write the code faster than I can generate it using these tools. That said, I think what the questioner proposes would be a time saver.
Jeff Leonard
A: 

The Zeus editor can be configured to do this using it's template feature as follows.

Step 1: Create a c:\temp\test.tpl file 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, Options menu to add the following template:

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

Step 3: Using the File, New menu, type in the word Bar, place the cursor on the word Bar and run the newly created template and you 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)
{
}
jussij
+1  A: 

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

While falling short of completely eliminating the need for writing class definitions, VA X has some nice "refactor" 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 similar member", which fills in the "add member" dialog with the data of an existing method or change the signature of a function and have it propagate to both the cpp and h files automatically.

It's not free, but well worth the money.

Jeroen

Jeroen
+1  A: 

For vim, I'm maintaining this suite that provides class snippets (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 done function after function.

Luc Hermitte
A: 

Eclipse surely has something related to this in it's refactoring menu though I haven't used it for a year and don't remember any specifics.

lhahne