1

編集: C++/CLI とは? 私は Visual studio でプログラミングをしていますが、私の知る限り C++ を使用しています... また、最初のエラーは Peter のコメントによって解決されましたが、2 番目のエラーはまだ解決されていません。

私は C++ の世界は初めてで、以前は Java ですべての作業を行っていました。私はポインターとガベージ コレクションの使用に慣れていませんが (概念は理解していると思いますが)、それが問題の原因である可能性があると考えています。次のエラー メッセージが表示されます。

1>Runner.cpp(6): error C3145: 'formOutOfTime' : global or static variable may not have managed type 'System::Windows::Forms::Form ^'
1>          may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
1>Runner.cpp(22): error C2061: syntax error : identifier 'FormOutOfTime'

私のコードは次のようなものです:

PurpleHealth.cpp (これは、システムがすべてを開始するために呼び出すと思われるファイルです):

#include "FormOutOfTime.h"

#include "FormParentalOverride.h"
#include "Runner.h"

using namespace PurpleHealth;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false); 

    // Create the main window and run it
    //Application::Run(gcnew FormOutOfTime());
    Runner* runner = new Runner();

    //delete runner;

    return 0;
}

Runner.h (これは、すべてのメイン コードを実行し、フォームを起動するヘッダー ファイルです。ヘッダー ファイルの背後にある目的にも苦労しています)

#include "stdafx.h"
#include "FormOutOfTime.h"
#include "FormParentalOverride.h"

class Runner
{
public:

    Runner();
    ~Runner();

    // functions

private:

    void Go();
    // member variables

};

最後に Runner.cpp:

#include "stdafx.h"
#include "Runner.h"
#include "FormOutOfTime.h"
#include "FormParentalOverride.h"
//Variable Dclaration
System::Windows::Forms::Form^ formOutOfTime;//Error Here***************************

Runner::Runner()
{
    // Do stuff if you need to

    this->Go();
}

Runner::~Runner()
{
    // Clear memory if you need to
}

void Runner::Go()
{
     formOutOfTime = gcnew FormOutOfTime();//Error Here***************************
    formOutOfTime->ShowDialog();
}

これらのメッセージを解決するのを手伝ってください。形式についての批評も大歓迎です。ありがとう。

4

1 に答える 1

2

マネージ ポインターは、静的スコープまたはグローバル スコープでは宣言できません。関数スコープでのみ宣言できます。formOutOfTime の宣言を runner.cpp ファイルの先頭から Go メソッド内に移動します。

于 2012-07-17T03:11:44.437 に答える