Where to put header files
-
I have just started to make my first MFC programs, and I am having a big problem. Whenever I alter the code and need to insert a heared file I recieve all kinds of errors. For example I am writing a program that contains a splitter window, with forms on both sides. In it I call splinterwnd.CreatView with a reference to the form class. But when I put the form header at the top I get errors (mainly c:\program files\microsoft visual studio\myprojects\temp\tempview.h(27) : error C2143: syntax error : missing ';' before '*') How do I know where to put the header file?
-
I have just started to make my first MFC programs, and I am having a big problem. Whenever I alter the code and need to insert a heared file I recieve all kinds of errors. For example I am writing a program that contains a splitter window, with forms on both sides. In it I call splinterwnd.CreatView with a reference to the form class. But when I put the form header at the top I get errors (mainly c:\program files\microsoft visual studio\myprojects\temp\tempview.h(27) : error C2143: syntax error : missing ';' before '*') How do I know where to put the header file?
This means that you need to include a header for whatever it is this line references. The header file goes in the top of the .h if it's for a member variable, otherwise the .cpp. It needs to be under the main ones (stdafx.h, the classes own header file ) and you need to make sure ( mainly by not putting it in the .h unless you need to ) that you don't create a circular reference where two headers load each other. More than that, I cannot tell without seeing the code. Christian I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in. The early bird may get the worm, but it's the second mouse that gets the cheese.
-
I have just started to make my first MFC programs, and I am having a big problem. Whenever I alter the code and need to insert a heared file I recieve all kinds of errors. For example I am writing a program that contains a splitter window, with forms on both sides. In it I call splinterwnd.CreatView with a reference to the form class. But when I put the form header at the top I get errors (mainly c:\program files\microsoft visual studio\myprojects\temp\tempview.h(27) : error C2143: syntax error : missing ';' before '*') How do I know where to put the header file?
This is something I wish someone would write an article on - with an aim of avoiding having to nest header includes in MFC projects. The problem arises as translation units include headers you're not expecting them to, and a nice directed include graph of an MFC app would be a boon. But here's a tip that might help - if you add a new class, include its header in the cpp file that holds the application class (MyApp.cpp) right after stdafx.h. Then, include it in whatever .cpp file will be using it, before the header for that file. The application class is typically the first translation unit to get compiled in these projects, and often the scope of its includes (doc and view, e.g.) are what cause the kaffufle. later... Actually, on reading your message again, you might be able to just get by with a forward declation of the form class at the top of the header, since you are just declaring a pointer. ---- "If you would see the invisible, you must look carefully at the visible." Santayana