If I compile the source code above, I get the following compiler error:
../CommunicationFrameHeader.cpp:8: error: prototype for `unsigned char myNamespace::CommunicationFrameHeader::fooBar(const myNamespace::CommunicationDirection&, const myNamespace::TransmissionType&)' does not match any in class `myNamespace::CommunicationFrameHeader'
subdir.mk:27: recipe for target `CommunicationFrameHeader.o' failed
../CommunicationFrameHeader.h:12: error: candidate is: static unsigned char myNamespace::CommunicationFrameHeader::fooBar(const CommunicationDirection&, const TransmissionType&)
make: *** [CommunicationFrameHeader.o] Error 1
The source code compiles without any error if I remove the namespace 'myNamespace' from all source files. So I think the problem is caused by the namespaces. But I don't know why, because all classes are in the same namespace. Any suggestions?
Your issue could possibly be cured by rearranging the inclusion order of
the include file in the CommunicationFrameHeader.cpp: file - but the real answer is to move the forward declaration for class CommunicationDirection; and class TransmissionType; inside the namespace myNamespace brackets - like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//move the forward declaratins here.
staticunsignedchar fooBar(const CommunicationDirection& communicationDirection, const TransmissionType& transmissionType);
#endif /* COMMUNICATIONFRAMEHEADER_H_ */
This basically ensures that the compiler know that the classes being forward declared are part of the myNameSpace scope.
The way you have them at the moment, and the way your files include each other makes it look like they are in the GLOBAL namespace scope.