无法从头文件访问功能 [英] Can't access function from header file

查看:141
本文介绍了无法从头文件访问功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//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 ++项目给出以下错误:

While buliding in Visual studio 2005, this vc++ project is giving following error:

error C3861: 'sum': identifier not found.

有人可以帮我吗?

推荐答案

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

You need to place the inclusion of head.h after stdafx.h. When precompiled headers are enabled the compiler will ignore the contents of all includes that occur prior to (in this case) the inclusion of stdafx.h .

这篇关于无法从头文件访问功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆