On Sun, 8 Apr 2007 12:15:55 +0200, "Bo Persson" <bo*@gmb.dkwrote:
>Bo Berglund wrote:
:: I have defined a few functions in a file, let's say it is called
:: functions.cpp. There are no objects involved, these are pure simple
:: functions.
::
:: In my test application I want to call this function so in the code I
:: reach by doubleclicking the button in the IDE I enter:
:: InitKey();
::
:: But when I compile this VS2005 displays an error:
:: 1>c:\engineering\vs2005\vstest32\vstest32\MainForm .h(119) : error
:: C2065: 'InitKey' : undeclared identifier
::
:: But it *is* declared in my file functions.cpp and this file *is*
:: listed among the project files...
::
:: Is there something else I have to do?
::
:: Note: I am a Delphi/VisualBasic programmer and have used ANSI C a
:: long time ago. I am a complte newbie to C++, but I have to port some
:: code into this environment.
:: At the time I wrote ANSI C such functions were declared in a H file
:: and this was included into the using C file. But Visual Studio
:: actually brings me to a H file to begin with when I doubleclick the
:: button, so I am at a loss here. I expected to be brought to the
:: proper cpp file rather than to an h file. And there are no includes
:: inside the h file...
::
C++ works just like C with regards to .h files. The functions.cpp file
should have a functions.h file declaring those functions that are supposed
to be called from somewhere else. Then #include this .h file "somewhere
else", to make the functions visible there.
You could also consider a better name than functions.cpp for this file. :-)
That was just an example name I made up...
Now I have created the real h file SentinelAGI.h and put a reference
into the MainForm.h as follows (finish part of file shown):
<snipped automatically generated stuff that I don't understand>
#pragma endregion <== What is this????
#include "SentinelAGI.h" <== reference to my new h file
private: System::Void MainForm_Load(System::Object^ sender,
System::EventArgs^ e) {
}
private: System::Void btnInit_Click(System::Object^ sender,
System::EventArgs^ e) {
lblInit.Text = "Start";
if (InitKey)
{ MainForm.lblInit.Text = "OK";
}
else
{ MainForm.lblInit.Text = "Error";
}
}
private: System::Void btnFindKey_Click(System::Object^ sender,
System::EventArgs^ e) {
}
};
}
I have added the SentinelAGI.h file to the project as a "header" file.
It is located in a subdir of its own.
Now VS2005 generates this error:
1>c:\engineering\vs2005\vstest32\vstest32\MainForm .h(115) : fatal
error C1083: Cannot open include file: 'SentinelAGI.h': No such file
or directory
Why can it not find a file that is clearly part of the project????
Bo Berglund
bo.berglund(at)nospam.telia.com