//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.
谁能帮我解决这个问题?
最佳答案
您需要将 head.h 包含在 stdafx.h 之后。启用预编译 header 时,编译器将忽略在(在本例中)包含 stdafx.h 之前发生的所有包含的内容。
关于c++ - 无法从头文件访问函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6742699/