7

Hi im trying to define an alias called USHORT.

// Demonstrates typedef keyword
#include <iostream>

typedef unsigned short int USHORT;  // typedef defined

main() {
    USHORT  Width = 5;
    USHORT Length;
    Length = 10;
    USHORT Area  = Width * Length;
    std::cout << "Width:" << Width << "\n";
    std::cout << "Length: "  << Length << std::endl;
    std::cout << "Area: " << Area;
}

I keep getting a compiler error saying:

Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\naqvi-home\documents\justit\c++\w1\cp1\list0304.cpp 8 1 ConsoleApplication3

Thanks

Scott
  • 4,974
  • 6
  • 35
  • 62
Rehan Naqvi
  • 243
  • 2
  • 4
  • 12

3 Answers3

13

It has nothing to do with your typedef. The problem is that you haven't given a return type for main:

int main()
{
  // ...
}

A function must have a return type. The main function must return int.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
  • just added a return 0 to the end of the main, still has the same problem. – Rehan Naqvi Mar 03 '13 at 14:03
  • 1
    @RehanNaqvi You need to say that the return type is `int`. See the example I gave. – Joseph Mansfield Mar 03 '13 at 14:04
  • ok thanks mate works now. sorry im new to c++ lol btw i just was curious , is the syntax when coding in c++ with a text editor different to coding within an ide. For example i with "#include " in a text editor would it be the same or would i have to change it to "#include ". Same goes for when you want to "cout", in an ide it seems i have to do "std::cout" whereas in a text editor i could just do "cout" without the pre "std::" – Rehan Naqvi Mar 03 '13 at 14:09
  • 1
    @RehanNaqvi The syntax for C++ is the same everywhere. An IDE is just a glorified text editor. There is no header `iostream.h`, you should do `#include `. All of the C++ library headers *do not* end in `.h`. However, the C library headers *do*. When you `#include `, the `cout` object is in the `std` namespace - you must qualify it with `std::cout` (unless you do something like `using namespace std;` - but that is **very naughty**). – Joseph Mansfield Mar 03 '13 at 14:12
3

You can easily look up the explanation for the error, by googling the error code. E.g. googling for 'C4430' would lead you here. The reason is, as others have stated, that you haven't declared the return type for main function.

Zdeslav Vojkovic
  • 14,391
  • 32
  • 45
2

I don't believe you need the extra int in the typedef, I thought from memory unsigned short (by default) is an int.

TheLazyChap
  • 1,852
  • 1
  • 19
  • 32