0

最近、Microsoft Visual C++ 2010 Express をダウンロードして C++ を学習しようとしましたが、問題が発生しました。以前に Java で Eclipse を使用したことがありますが、Microsoft Visual C++ はそれに似ているようです。

したがって、私の問題は、Project というプロジェクトを作成し、プロジェクトに 2 つのファイル (HelloWorld.cpp と PowersOfTwo.cpp) があることです。HelloWorld.cpp のコードは次のとおりです。

 /* 
Hello World File
*/

#include <iostream>
using namespace std;

int main()
{
    cout<< "Hello, World" << endl;

    return 0;

}

PowersOfTwo.cpp コードは次のとおりです。

    /*
This program generates the powers of two
until the number that the user requested
*/

#include <iostream>
using namespace std;

int raiseToPower(int n, int k);

int main()
{
    int limit;
    cout << "This program lists the powers of two. " << endl;
    cout << "Enter exponent limit: ";
    cin >> limit;

    for (int i = 0; i <= limit; i++)
    {
        cout << "2 to the " << i << " = " << raiseToPower(2, i) << endl;
    }

    return 0;
}

/* Function for raiseToPower */

int raiseToPower(int n, int k)
{
    int result = 1;
    for (int i = 0; i < k; i++)
    {
        result *= n;
    }
    return result;

}

基本的に、PowersOfTwo.cpp ファイルをデバッグせずに開始しようとしましたが、HelloWorld.obj で _main が既に定義されているという致命的なエラーが発生しました。それは、同じプロジェクトでメイン メソッドを持つ 2 つのファイルを持つことができないということですか (メイン メソッドを持つ 2 つのファイルを持つことができるときの eclipse とは対照的です)。それはまた、無関係なプログラムが機能するために毎回新しいプロジェクトを作成する必要があるということですか?

4

2 に答える 2