c++ - 无法从头文件访问函数

标签 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.

谁能帮我解决这个问题?

最佳答案

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

关于c++ - 无法从头文件访问函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6742699/

相关文章:

c++ - 如何在 C++ 中确定进程所有者是否是 Mac OS X 上的管理员

c++ - 作为参数发送时增加指针的值

c++ - 如何从另一个 C++ win32 控制台应用程序调用 C++ Win32 DLL

c++ - 系统范围的热键快捷方式(Windows/Qt) : Prevent window lock?

c++ - 确保派生类实现静态方法

c++ - 将类的实例返回给 main

c++ - ON_REGISTERED_MESSAGE Win32 等效项

c++ - 如何用C++读取Windows默认网关IP地址

visual-studio - fatal error C1010 : unexpected end of file while looking for precompiled header. 您是否忘记将 '#include "StdAfx.h"' 添加到您的源代码中?

c++ - 关于我的编译器中缺少的 stdafx.h(Windows 上的 mingw32)