<tfoot id='WMMMA'></tfoot>

<small id='WMMMA'></small><noframes id='WMMMA'>

      <legend id='WMMMA'><style id='WMMMA'><dir id='WMMMA'><q id='WMMMA'></q></dir></style></legend>
    1. <i id='WMMMA'><tr id='WMMMA'><dt id='WMMMA'><q id='WMMMA'><span id='WMMMA'><b id='WMMMA'><form id='WMMMA'><ins id='WMMMA'></ins><ul id='WMMMA'></ul><sub id='WMMMA'></sub></form><legend id='WMMMA'></legend><bdo id='WMMMA'><pre id='WMMMA'><center id='WMMMA'></center></pre></bdo></b><th id='WMMMA'></th></span></q></dt></tr></i><div id='WMMMA'><tfoot id='WMMMA'></tfoot><dl id='WMMMA'><fieldset id='WMMMA'></fieldset></dl></div>
        <bdo id='WMMMA'></bdo><ul id='WMMMA'></ul>
      1. StdAfx + 头文件 - MFC 应用程序中的包含顺序

        StdAfx + Header file - Order of inclusion in MFC application(StdAfx + 头文件 - MFC 应用程序中的包含顺序)

        <small id='1ES6d'></small><noframes id='1ES6d'>

          <tbody id='1ES6d'></tbody>
          <tfoot id='1ES6d'></tfoot>
              • <bdo id='1ES6d'></bdo><ul id='1ES6d'></ul>

                1. <legend id='1ES6d'><style id='1ES6d'><dir id='1ES6d'><q id='1ES6d'></q></dir></style></legend>

                2. <i id='1ES6d'><tr id='1ES6d'><dt id='1ES6d'><q id='1ES6d'><span id='1ES6d'><b id='1ES6d'><form id='1ES6d'><ins id='1ES6d'></ins><ul id='1ES6d'></ul><sub id='1ES6d'></sub></form><legend id='1ES6d'></legend><bdo id='1ES6d'><pre id='1ES6d'><center id='1ES6d'></center></pre></bdo></b><th id='1ES6d'></th></span></q></dt></tr></i><div id='1ES6d'><tfoot id='1ES6d'></tfoot><dl id='1ES6d'><fieldset id='1ES6d'></fieldset></dl></div>

                3. 本文介绍了StdAfx + 头文件 - MFC 应用程序中的包含顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用的是 Visual Studio 2005.我创建了一个名为StdAfx 依赖"的基于 MFC 的控制台应用程序.IDE 为我创建了以下文件.

                  I am using Visual Studio 2005. I created an MFC based console application named "StdAfx dependancy". The IDE created the following files for me.

                  1. 资源.h
                  2. StdAfx Dependancy.h
                  3. stdafx.h
                  4. StdAfx Dependancy.cpp
                  5. stdafx.cpp

                  我添加了另一个类 CHelper 和 Helper.h 和 Helper.cpp,如下所示.

                  I added another class CHelper with Helper.h and Helper.cpp as below.

                  Helper.h:

                  #pragma once
                  
                  class CHelper
                  {
                  public:
                      CHelper(void);
                      ~CHelper(void);
                  };
                  

                  Helper.cpp

                  #include "StdAfx.h"
                  #include "Helper.h"
                  
                  CHelper::CHelper(void)
                  {
                  }
                  
                  CHelper::~CHelper(void)
                  {
                  }
                  

                  我在主函数中为CHelper创建了一个对象;为此,我在 StdAfx Dependancy.cpp 的第一行中添加了 Header.h 文件,如下所示;我收到了以下错误.

                  I created an object for CHelper in the main function; to achieve this I added Header.h file in the first line of StdAfx Dependancy.cpp as below; and I got the following errors.

                  d:codesstdafx 依赖项stdafx依赖stdafx依赖.cpp(33):错误 C2065:CHelper":未声明标识符
                  d:codesstdafx依赖stdafx 依赖stdafxdependancy.cpp(33):错误 C2146:语法错误:缺少;"前标识符myHelper"
                  d:codesstdafx依赖stdafx 依赖stdafxdependancy.cpp(33):错误 C2065:'myHelper' : 未声明的标识符

                  d:codesstdafx dependancystdafx dependancystdafx dependancy.cpp(33) : error C2065: 'CHelper' : undeclared identifier
                  d:codesstdafx dependancystdafx dependancystdafx dependancy.cpp(33) : error C2146: syntax error : missing ';' before identifier 'myHelper'
                  d:codesstdafx dependancystdafx dependancystdafx dependancy.cpp(33) : error C2065: 'myHelper' : undeclared identifier

                  但是当我在 stdafx.h 之后包含它时,错误消失了.为什么?

                  But when I include it after stdafx.h, the error vanishes. Why?

                  // Stdafx dependancy.cpp : Defines the entry point for the console application.
                  //
                  
                  #include "Helper.h"
                  
                  #include "stdafx.h"
                  #include "Stdafx dependancy.h"
                  
                  // #include "Helper.h" --> If I include it here, there is no compilation error
                  
                  #ifdef _DEBUG
                  #define new DEBUG_NEW
                  #endif
                  
                  
                  // The one and only application object
                  
                  CWinApp theApp;
                  
                  using namespace std;
                  
                  int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
                  {
                      int nRetCode = 0;
                  
                      // initialize MFC and print and error on failure
                      if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
                      {
                          // TODO: change error code to suit your needs
                          _tprintf(_T("Fatal Error: MFC initialization failed
                  "));
                          nRetCode = 1;
                      }
                      else
                      {
                          CHelper myHelper;
                      }
                  
                      return nRetCode;
                  }
                  

                  推荐答案

                  这个链接一定会给你一些线索.stdafx.h 的目的

                  This link must give you some clue. Purpose of stdafx.h

                  在之前定义的行#include "stdafx.h" 被编译器忽略.因此,如果您想真正包含这些文件,那么您需要将它们包含在 #include "stdafx.h" 之后.

                  The lines defined before the #include "stdafx.h" are ignored by the compiler. So if you want to actually include those files then you need to include them after the #include "stdafx.h".

                  希望它很清楚.

                  这篇关于StdAfx + 头文件 - MFC 应用程序中的包含顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Consistent pseudo-random numbers across platforms(跨平台一致的伪随机数)
                  Vary range of uniform_int_distribution(改变uniform_int_distribution的范围)
                  What is a seed in terms of generating a random number?(就生成随机数而言,种子是什么?)
                  Is 1.0 a valid output from std::generate_canonical?(1.0 是 std::generate_canonical 的有效输出吗?)
                  Getting big random numbers in C/C++(在 C/C++ 中获取大随机数)
                  What is the best way to generate random numbers in C++?(在 C++ 中生成随机数的最佳方法是什么?)

                    <small id='WUC8X'></small><noframes id='WUC8X'>

                      <tbody id='WUC8X'></tbody>
                    • <i id='WUC8X'><tr id='WUC8X'><dt id='WUC8X'><q id='WUC8X'><span id='WUC8X'><b id='WUC8X'><form id='WUC8X'><ins id='WUC8X'></ins><ul id='WUC8X'></ul><sub id='WUC8X'></sub></form><legend id='WUC8X'></legend><bdo id='WUC8X'><pre id='WUC8X'><center id='WUC8X'></center></pre></bdo></b><th id='WUC8X'></th></span></q></dt></tr></i><div id='WUC8X'><tfoot id='WUC8X'></tfoot><dl id='WUC8X'><fieldset id='WUC8X'></fieldset></dl></div>
                      <legend id='WUC8X'><style id='WUC8X'><dir id='WUC8X'><q id='WUC8X'></q></dir></style></legend>

                          • <bdo id='WUC8X'></bdo><ul id='WUC8X'></ul>
                            <tfoot id='WUC8X'></tfoot>