Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Visual C++ 2005 Express Edition - C4430 error

Status
Not open for further replies.

Designware

Technical User
Sep 24, 2002
202
Hi,

My son is learning C++ in his high school class, and I don't know C++ at all. He brought his source code home, and we loaded it into the free Express Edition and it would not run. He then created a most simple program to see if he could get it to run. Here is the source.

#include <iostream>
using namespace std;
main()
{
cout<<"Hello"<<endl;
return 0;
}

It then gives the error message: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

At school, he can get this to run, but not here. What do we need to do different using the Express Edition? (I know we can't create a compiled program with this Express Edition, but we don't want or need to.)

Thanks in advance for your help.

Dale
 
main() doesn't have any return value specified. main() should always return an int.
Code:
#include <iostream>

using namespace std;

[b]int[/b] main()
{
   cout << "Hello World" << endl;
   return 0;
}
 
In the old days, in C, if you didn't specify a return type or declare a parameter, it defaulted to int. For instance
Code:
mult (x,y)
{
   return x * y;
}
You may still find some compilers which will accept this but they are very rare. The last time I used a compiler that accepted this was 1989.

Nowadays, everything must be declared up front. The main reason being people forgetting to fill in types and spending ages tracking down errors where wrong types have been assumed. So the above would now look like
Code:
int mult (int x, int y)
{
   return x * y;
}
If there is no return value, void should be specified. main is special: it always returns int.
 
Thank you both for your responses. You were right on the money. However, as soon as that error disappeared, several others (4) appeared. Is there a simple book I can buy to get me started? His textbook hasn't been of much assistance.

I find it interesting that such a simple program creates so many errors.

Thanks again.
 
That code is correct with cpjust's correction. If you would like some advice on those other 4 errors you might want to post the error messages for them as well. It might be something simple and/or important.

As for books, the best book to learn C++ is Accelerated C++ by Koenig and Moo. However, this book is accelerated as its name implies, and if your son is a high school student, it might go a little too quickly for him.

The problem is that there are a lot of out of date books available to learn C++. Even of those that have been published recently, many teach old or C style C++. While this is acceptable if you just want to learn some programming basics, it leaves students with bad habits if they want to write good C++ code.

Another option is C++ Primer by Lippman, LaJoie and Moo (make sure to get the latest version that includes Moo as an author). Perhaps that and the Accelerated C++ book will be enough to keep your son understanding and learning C++.

By the way, I don't think there is any textbook to get you started with using the standard C++ part of the Visual C++ Express IDE. You might find some tutorials online. You can also just ask questions in C++ forums, although you might consider a different one like cprogramming.com since this site is geared towards professionals and homework style questions often get removed.

Hope that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top