0

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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

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_ */

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.