为什么自己编写的C++类的.cpp文件必须包含stdafx.h这个头文件?
我自己用VC编写了一个非常简单的C++ 类:
/***************************************/
/* MyClass.h */
/***************************************/
#if !defined _MYCLASS_H
#define _MYCLASS_H
#include "stdio.h"
class MyClass
{
public:
int GetX() { return m_x; }
int GetY() { return m_y; }
void SetX(int x) { m_x = x; }
void SetY(int y) { m_y = y; }
int add(int x, int y);
public:
int m_x;
int m_y;
};
#endif
/*************************************/
/* MyClass.cpp */
/*************************************/
#include "stdafx.h"
#include "myclass.h"
int MyClass::add(int x,int y)
{
printf("\n add(x,y) = %d",x+y);
return x+y;
}
我发现:如果在MyClass.cpp中去掉 :#include "stdafx.h"
则编译提示错误:
fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.
但是如果加上#include "stdafx.h",就不会提示编译错误?
难道自己编写一个类必须包含stdafx.h这个头文件?