无法从头文件访问功能

时间:2011-07-19 05:37:08

标签: c++ visual-c++ stdafx.h

//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.

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

2 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:3)

从项目中删除stdafx.h,并转换预编译的头文件..或者尝试将head.h移动到之后的,而不是之前的