Hi guys,

I've been using C++ for quite a while now, maybe around a year and something has always bothered me but I've never discovered a better way to deal with it.

When I define a class I will always define a header file. As an example take this:

foo.h

#ifndef FOO_H_
#define FOO_H_

class foo {
public:
	foo();
	virtual ~foo();
};
#endif /* FOO_H_ */

foo.cpp

#include "foo.h"

foo::foo() 
{

}

foo::~foo() 
{

}

Now consider I want to add a method to foo, I have to first add it to the header file and then I have to add it to the cpp file. Then consider I want to change the arguments, or maybe return type, of the method. Again, I have to change it in two places.

This isn't a problem really but I just find it tedious to add new methods and update them as I code.

Does anyone have any tips for me? Maybe tools which do this sort of thing for me?

Thanks in advance,

Martin

You can put the implementation code in the header file (called inline functions) and not use the implementation file. But I'd only use this technique for small methods.

#ifndef FOO_H_
#define FOO_H_

class foo {
public:
    foo()
    {
       _x = 0;
    {
    virtual ~foo()
    {

    {
    void SayHello()
    {
       cout << "Hello\n";
    }
private:
    int _x;
};
#endif /* FOO_H_ */
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.