相关疑难解决方法(0)

什么是Visual Studio中使用的"stdafx.h"?

stdafx.h我在Visual Studio 2010中启动项目时会自动生成一个名为的文件.我需要创建一个跨平台的C++库,所以我不能/不能使用这个头文件.

什么stdafx.h用于?我可以删除这个头文件吗?

cross-platform visual-studio-2010 stdafx.h visual-studio visual-c++

488
推荐指数
3
解决办法
42万
查看次数

StdAfx +头文件 - MFC应用程序中包含的顺序

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

  1. RESOURCE.H
  2. StdAfx Dependancy.h
  3. stdafx.h中
  4. StdAfx Dependancy.cpp
  5. stdafx.cpp

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

Helper.h:

#pragma once

class CHelper
{
public:
    CHelper(void);
    ~CHelper(void);
};
Run Code Online (Sandbox Code Playgroud)

Helper.cpp

#include "StdAfx.h"
#include "Helper.h"

CHelper::CHelper(void)
{
}

CHelper::~CHelper(void)
{
}
Run Code Online (Sandbox Code Playgroud)

CHelper在main函数中创建了一个对象; 为实现这一点,我在StdAfx Dependancy.cpp的第一行添加了Header.h文件,如下所示; 我有以下错误.

d:\ codes\stdafx dependancy\stdafx dependancy\stdafx dependancy.cpp(33):error C2065:'CHelper':未声明的标识符
d:\ codes\stdafx dependancy\stdafx dependancy\stdafx dependancy.cpp(33):error C2146:语法错误:缺少';' 在标识符'myHelper'之前
d:\ codes\stdafx dependancy\stdafx dependancy\stdafx dependancy.cpp(33):error C2065:'myHelper':未声明的标识符

但是当我把它包括在内之后stdafx.h,错误就消失了.为什么?

// Stdafx dependancy.cpp : Defines the entry point for the console application.
//

#include "Helper.h"

#include "stdafx.h" …
Run Code Online (Sandbox Code Playgroud)

c++ mfc compiler-errors stdafx.h visual-c++

2
推荐指数
1
解决办法
2350
查看次数