August 2nd, 2004, 10:13 am
You need an explicit reference to the header file in your .cpp , or in stdafx.hOne does not normally add library header files to a project because they don't change.However, if you are building your own, they will change, in which case you need to tell the environment that your code is dependant upon it, since you need to recompile for each change to a header file. MJ's advice is right, but I would add the caveat that you should never ever have two copies of the same header file.This can do really bad things to you, your health and wealth, and the ozone layer.Consider a classclass MyClass{ public: double, thing, otherthing, mything, something_else;};This is in one copy of a header file.Imagine that someone adds a field:class MyClass{ public: double, thing, otherthing, mything,something_else, athing;};If no reference is made to "athing", then both will happily compile in either project. Indeed, if you explicitly load particular header files by using "MyHeader" rather than <MyHeader> which searches a path you can compile the same executable with both.However, imagine that a DLL or .OBJ is compiled with one definition of MyClass, and is used by some code with the other definition.There's a good chance this code will work.For a while...At the very least you can fear memory leaks, where one piece of code frees up memory based upon a smaller definition.A more likely effect is that small lumps of memory will change values when you least expect them to.Whatever version of the class you use, the debugger will only have one, it will give misleading results, since it may be looking in the wrong place for things.If you use the browser functionality, it will typically be consistent with what the deugger believes. Thus you may assign to "athing" in one piece of code, and see it get there, but when you step through to a difference bit of code the value will magically change. This may happen in a simple statement like x=y, where neither x, nor y have anything to do with MyClass.That's if you're lucky...If you're unlucky it will occur in a really ugly line of code, or better still in a 3rd party library you don't trust, and will thus blame.Happens in reverse as well, you will assign to a member, and it will overwrite the memory that belongs to another variable. If you have a lot of arrays, then at some point one value in it will change. Will you spot this ? No.If you're writing multi threaded apps, then it will be hard to hunt this bug down. Of course you don't know it's this type of bug, so you have no idea where to start looking.You're looking for 8 bytes, somewhere in two billion that change, sometimes.Sorry to go on, but this is a real world problem my team fought. You don't want to go there.