What is a good rule to organize C++ code?

I wonder is there any rules to help organize our source code? For example, I'm having some header files and CPP files. Its structure looks like this:

1
2
3
4
5
6
7
8
9
10
- main.cpp
- /includes
	- All.h
	- ModA.h
	- ModB.h
	- ModC.h
- /modules
	- ModA.cpp
	- ModB.cpp
	- ModC.cpp



In All.h, I #include ModA.h, ModB.h, ModC.h and any std libraries I need. In every Mod*.cpp, I just include All.h header. This seems ok at first, however, it seems to be slow in compiled time.

If I include selected headers for specific cpp file than it quite... annoy. It usually caused 'redefinition of 'length' as different kind of symbol' error even though I can see it anywhere.

Is there any ways could achieve these (expectation):
- Quick compiled time
- Easy to maintain
- Less tangling with `redefinition` error

Thanks in advance, guys.

Last edited on
It usually caused 'redefinition of 'length' as different kind of symbol' error even though I can see it anywhere.
This is certainly not a natural effect of different organization of includes.

I would guess that you might have a problem with a macro (#define) or 'using namespace'.
Thanks, can you help me to point out the root of the problem of my code? Here is it (https://repl.it/@dangtu/HTMG --> File: Node.cpp and NamedNodeMap.cpp)

I would like to here your opinion.
This is of course a problem:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef	NAMED_NODE_MAP_H
#define	NAMED_NODE_MAP_H

namespace dt
{
	class NamedNodeMap
	{
		unsigned long int	length; // A member variable

		public:
			unsigned long int length(); // A member function with the same name => redefinition
			
			virtual Node	getNamedItem(DOMString) = 0;
			virtual Node	setNamedItem(std::vector<Node>) = 0;
			virtual Node	removeNamedItem(DOMString) = 0;
			virtual Node	item(unsigned long int) = 0;
	};
}
#endif 
These redifinitions appear multiple times within your headers.
Topic archived. No new replies allowed.