C++ Can';t从头文件访问函数

C++ Can';t从头文件访问函数,c++,visual-c++,stdafx.h,C++,Visual C++,Stdafx.h,在Visual studio 2005中构建时,此vc++项目出现以下错误: //mainfn.cpp// #include "head.h" #include "stdafx.h" #include string #include iostream #include stdio.h using std::string; using std::cout; using namespace System; int main() { int x=10,y=2; printf("value: %d

在Visual studio 2005中构建时,此vc++项目出现以下错误:

//mainfn.cpp//

#include "head.h"
#include "stdafx.h"
#include string
#include iostream
#include stdio.h
using std::string;
using std::cout;
using namespace System;

int main()
{
int x=10,y=2;
printf("value:  %d",sum(x,y));
Console::ReadLine();
return 0;
}

有谁能帮我解决这个问题吗?

您需要将head.h包含在stdafx.h之后。启用预编译头后,编译器将忽略(在本例中)包含stdafx.h之前发生的所有包含的内容。

从项目中删除stdafx.h,然后打开预编译头。。或者尝试将head.h移动到stdafx.h之后而不是之前。

stdafx.h中有什么内容,以及您的预编译头设置是什么?可能您在预编译头文件中遇到了一些奇怪的情况,因为发布的代码没有问题。事实上,当我在visual studio中启动新的VC++项目时,始终包含此预编译头文件。thnx chet。。为了纠正这个愚蠢的错误,我们付出了很多。现在好了。@durgesh t:如果好的话,你可能想接受这个人的回答
//head.cpp//

#include "head.h"
#include "stdafx.h"
int sum(int x, int y)
{
return (x+y);
}
//mainfn.cpp//

#include "head.h"
#include "stdafx.h"
#include string
#include iostream
#include stdio.h
using std::string;
using std::cout;
using namespace System;

int main()
{
int x=10,y=2;
printf("value:  %d",sum(x,y));
Console::ReadLine();
return 0;
}
error C3861: 'sum': identifier not found.