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

誰かがこれで私を助けることができますか?

4

2 に答える 2

6

stdafx.hの後にhead.h を含める必要があります。プリコンパイル済みヘッダーが有効になっている場合、コンパイラはstdafx.hを含める前(この場合)に発生するすべてのインクルードの内容を無視します。

于 2011-07-19T05:55:51.663 に答える
3

Either remove stdafx.h from the project, and turn of precompiled headers.. or try moving head.h to be included after stdafx.h instead of before.

于 2011-07-19T06:50:02.340 に答える