Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access function from header file

//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;
}

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

error C3861: 'sum': identifier not found.

Can anybody help me out with this?

like image 894
DTdev Avatar asked Mar 13 '26 16:03

DTdev


1 Answers

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 .

like image 122
Captain Obvlious Avatar answered Mar 15 '26 04:03

Captain Obvlious



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!