basil001
asked on
need help with a single #include statement that gives 102 errors!
hi all,
in a .cpp file created for implementing member functions of the View class
i put: #include "CMyView.h"
and a bunch of errors appear.
The same happens if i try to include the Document class.
Only 8 errors appear when using #include "StdAfx.h" before the other.
would appreciate any kind of help :)
in a .cpp file created for implementing member functions of the View class
i put: #include "CMyView.h"
and a bunch of errors appear.
The same happens if i try to include the Document class.
Only 8 errors appear when using #include "StdAfx.h" before the other.
would appreciate any kind of help :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If it works, it is the normal procedure.
what are some of the errors? Remember, if a header file is included more than once in a compile, it can give you errors about redefinitions. For instance, if SampleView.h above has the following:
#include "SampleDoc.h"
and your main program has the includes you listed, you could get errors because you are basically including SampleDoc.h twice.
However, a good practice to do in a .h file is this:
// SampleDoc.h
#ifndef SAMPLEDOC_H
#define SAMPLEDOC_H
... // put everything else here
#endif
When you create a class with the ClassWizard, it will generate this for you, but use some long weird string. Basically, what it's doing is only including the file if it hasn't been included yet. It checks if it has a definition for SAMPLEDOC_H, and if it does, it skips everything between the #ifndef and #endif
The only catch is that you MUST make sure that every header file in your compile has a different definition. I like to use the filename, with an underscore replacing the dot, but it can be anything as long as it is unique from any other file you are including.
If this isn't the problem, try listing some of your errors and maybe that will help
#include "SampleDoc.h"
and your main program has the includes you listed, you could get errors because you are basically including SampleDoc.h twice.
However, a good practice to do in a .h file is this:
// SampleDoc.h
#ifndef SAMPLEDOC_H
#define SAMPLEDOC_H
... // put everything else here
#endif
When you create a class with the ClassWizard, it will generate this for you, but use some long weird string. Basically, what it's doing is only including the file if it hasn't been included yet. It checks if it has a definition for SAMPLEDOC_H, and if it does, it skips everything between the #ifndef and #endif
The only catch is that you MUST make sure that every header file in your compile has a different definition. I like to use the filename, with an underscore replacing the dot, but it can be anything as long as it is unique from any other file you are including.
If this isn't the problem, try listing some of your errors and maybe that will help
ASKER
but i want to implement function members of the class in a separate .cpp file, to keep the SampleView.cpp not very long.
So i create a .cpp file, include the View Class header function SampleView.h, and still the same lot of errors; even if only the "#include SampleView.h" exists in the cpp file created.
AH, it works if the four includes are inserted on the new .cpp:
#include "stdafx.h"
#include "SampleApp.h" // application
#include "SampleDoc.h" // document
#include "SampleView.h"
Is this the normal procedure to follow when you want to implement class function members on different files?
thanks