2
//head.h//
extern int sum(int,int);
//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;
}

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

error C3861: 'sum': identifier not found.

有人可以帮我解决这个问题吗?

4

2 回答 2

6

您需要将head.h包含 stdafx.h之后。启用预编译头文件时,编译器将忽略在包含stdafx.h之前(在这种情况下)发生的所有包含的内容。

于 2011-07-19T05:55:51.663 回答
3

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

于 2011-07-19T06:50:02.340 回答