Hello,
I am new to C++, coming from a background in Java and procedural languages. I am currently translating some code from Java to C++ as an exercise and have run into the following problem:
File a.h contains some constant definitions.
As a protection against multiple definitions of these constants I included the following lines at the top of it:
#ifndef const_file_def
#define const_file_def
and added at the end:
#endif
The classes defined in files b.h/b.cpp and c.h/c.cpp both need these definitions and therefore #include a.h
The class defined in files d.h/d.cpp makes use of both b and c classes, and so is compiled as follows:
c++ -o d.out d.cpp b.o c.o
where b.o and c.o were created earlier with a c++ -c command.
The problem is that despite my #ifndef clause at the top of a.h I still get a "multiple definition of " error for every constant defined in it.
How can I avoid the multiple definitions?
Many thanks,
Abe