ここに簡単な C++ プログラムがあります。
#include <iostream>
using namespace std;
main () //no return type for main. Yet program compiles and runs ok
{ //when run by itself.
cout << "hi";
}
しかし、次のような別のファイルに空の単体テストを追加すると、プログラムはコンパイルされなくなりますnewsimpletest1.cpp
。
#include <stdlib.h>
#include <iostream>
int main(int argc, char** argv) {
}
実行すると、期待どおりにコンパイルされ、「hi」が出力されます。しかし、プロジェクトをテストすると、エラーが発生します。
error: ISO C++ forbids declaration of `__nomain' with no type
戻り値の型「int」を「main」に追加すると、正しくコンパイルおよび実行されます。このエラーが何を伝えようとしているのかを理解しようとしています。
デフォルトの g++ コンパイラを使用して、Netbeans 7.1.2 でコンパイルする Windows XP を使用しています。