I have used include guards many times before, but never really understood how or why they work.
Why doesn't the following work?
#ifndef CAMERA_CLASS_HPP #define CAMERA_CLASS_HPP class camera_class { .... }; camera_class glcam = camera_class(); #endif // CAMERA_CLASS_HPP The error is this: (You can probably guess what it's going to be from the title of this question!)
-------------- Build: Debug in System --------------- Linking console executable: bin/Debug/System /usr/bin/ld: error: obj/Debug/main.o: multiple definition of 'glcam' /usr/bin/ld: obj/Debug/camera_class.o: previous definition here /usr/bin/ld: error: obj/Debug/main.glfunc.o: multiple definition of 'glcam' /usr/bin/ld: obj/Debug/camera_class.o: previous definition here collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 0 seconds) 0 errors, 0 warnings Also, could someone please explain to me why a header guard works?