"Jon Sturgeon" <Jo**@futuresoft.nospam.com> wrote in message news:4i********************************@4ax.com...
On Mon, 29 Sep 2003 10:06:29 -0700, "Jack" <ma*****@comcast.net> wrote:
The above failed to compile. It was complaining about
MessageBox being neither class nor namespace.
Before you can reference "MessageBox" (which I assume is one of your
classes?), you need to #include the header file that defines that
identifier.
Jon
Jon
MessageBox is a "build in" .NET class included in System.Windows.Forms
Also #include is already there. Try the following.
1) Start fresh new Windows Forms Apllication (.NET)
2) In the "Form1.h" file modify the Form1 constructor as follows:
Form1(void)
{
InitializeComponent();
MessageBox::Show(S"TEST",S"TEST"); // THIS IS THE MODIFICATION LINE ADDED
}
3) Compile it and run it. It runs OK with no errors and the expected .NET MessageBox shows up.
4) Now modify the project as follows: In the file Form1.h change the constructor from definition to declaration as
follows:
Form1(void); // This is file Form1.h
In the file Form1.cpp add constructor definition at the end of the file as follows:
Form1::Form1(void) // This is definition
{
InitializeComponent();
MessageBox::Show(S"TEST",S"TEST");
}
Notice, that file Form1.cpp already has #include "Form1.h" line above the new declaration.
5) When you try to compile this you will get the following error:
c:\Documents and Settings\Jacek\Documents\Programs\Vc\test\Form1.cp p(20): error C2653: 'MessageBoxA' : is not a
class or namespace name
Becuase #include "Form1.h" is in the file "Form1.cpp", anything that was "#included" or "using...ed" in the file
"Form1.h" should
theoretically and traditionally apply in file "Form1.cpp" after #include "Form1.h" line but obviously it is not.
My old school of C++ and C cannot explain this. Please help :-(
Jack