473,320 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why this is failing to compile.

I'm new to Visual C++ for .NET and during learning I
encountered the following:

In Form1.h file inside class Form1 following the book
example I defined fuction that looks like this:

(file Form1.h)

void function()
{
... some code ...
MessageBox::Show(....);
... some code ...
};

This compiled and worked OK. But because I'm from the old
world of C programming I wanted to move body of the
function to the Form1.cpp file as follows:

(file Form1.h)

void function();

(file Form1.cpp)

#include "Form1.h"

.... some code ...

void Form1::function()
{
... some code ...
MessageBox::Show(...);
... some sode ...
}

The above failed to compile. It was complaining about
MessageBox being neither class nor namespace.

Why it did not compile ?

Jack
Nov 16 '05 #1
3 1349
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

Nov 16 '05 #2
"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
Nov 16 '05 #3
On Tue, 30 Sep 2003 21:50:30 -0400, "Marchel" <ma*****@comcast.net>
wrote:
Jon

MessageBox is a "build in" .NET class included in System.Windows.Forms
Also #include is already there. Try the following.


Ah, sorry, I didn't realize this was a .NET framework question. Being
posted in the .vc newsgroup I rashly expected it to be a C++ related
issue :-)

I have very little experience with .NET so I'll leave your question for
somebody else...

Jon

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hanzo | last post by:
I'm currently fighting my way through an example of Single-Threaded Memory Pooling in a chapter of the Efficient C++ book by Dov Bulka & David Mayhew. Unfortuantely, I'm starting to get code that...
21
by: Mike MacSween | last post by:
Had some trouble with Word automation. Sorted it, in the process thought I would try late binding. Some people reccomend it. So this: *********************************************************...
11
by: Ken Allen | last post by:
I have been using C# for some time now, and for the most part I am very impressed, and prefer using it over C++. There is one area where C#/.Net seem, at least to me, to be less than desirable...
9
by: Nak | last post by:
Hi there, I have come across a rather frustrating bug with the 2002 VB.NET Standard IDE. I am currently developing an application framework to use my my new products, all is pretty straight...
0
by: Samuel M. Smith | last post by:
I am trying to build python2.4.2 on an arm 9 running Debian 3 Sarge when I run ./configure it fails with ../configure checking MACHDEP... linux2 checking EXTRAPLATDIR... checking for...
18
by: Scott David Daniels | last post by:
There has been a bit of discussion about a way of providing test cases in a test suite that _should_ work but don't. One of the rules has been the test suite should be runnable and silent at every...
0
by: bidalah | last post by:
Hi, I hope there is a simple, stupid answer to this. It's driving me up a wall. I am attempting to build ghostscript from source in Visual Studio 8. A challenge, but I finally got it working,...
10
by: dwaach | last post by:
Hi, I am trying to compile the following program, #include <iostream> using namespace std; typedef char* CHAR; typedef const CHAR CCHAR;
1
by: juan blanco | last post by:
Hi all, I am trying to compile / rebuild a solution with msbuild to be part of our continuous integration. One of the projects aliases a referenced project to resolve confilicting namespaces....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.