Question

I'm using VS 2013, and Horton C++ 2010.

My chapter exercise, Ex9_01.cpp, has strcpy_s() and strlen() in the class file CandyBox.h and it didn't work until I "#include cstring" in in CandyBox.h.

Then as I read more of the example I saw that "#include cstring" was in the source file, Ex9_01.cpp, so I removed "cstring" from CandyBox.h and example stilled worked!
WHY?
Since the file Candybox.h doesn't "#include Ex9_01.cpp" why does it look at Ex9_01.cpp to know about 'cstring'?

P.S. Sorry about poor formatting, this is my first post at site and I guess I didn't read all the instructions. Will do better next time (am short of time now, running for an airplane).

Astro

Was it helpful?

Solution

The compiler only looks at cpp files. An h file only gets compiled when it is #include'ed in a cpp file, just as if it had been pasted there. So what probably happens in your case is that the cpp file includes cstring.h, then it includes candybox.h. So cstring.h is "seen" before candybox.h.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top