无法从头文件访问函数

Can't access function from header file

本文关键字:访问 函数 文件      更新时间:2023-10-16
//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.
有谁能帮我一下吗?

您需要在 stdafx.h之后放置head.h。当启用预编译头文件时,编译器将忽略在stdafx.h .

之前出现的所有包含内容。

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