• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

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 :)
0
basil001
Asked:
basil001
  • 2
1 Solution
 
AlexFMCommented:
The standard set of #include lines in MFC View class is:

#include "stdafx.h"
#include "SampleApp.h"           // application

#include "SampleDoc.h"           // document
#include "SampleView.h"          // view

If yoy have such include lines and still have errors, give additional information.
0
 
basil001Author Commented:
Those includes appear on the View class .cpp file

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
0
 
AlexFMCommented:
If it works, it is the normal procedure.
0
 
sigmazero13Commented:
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now