私はここ数ヶ月C++/ CLIを学んでいますが、何を試しても、私が抱えている問題を解決できないようです。
String ^、Array ^、またはArrayList^データ型のいずれかをmain.cppからForm1.hに渡す必要があります。main.cppで変数をグローバルにしてから、externを使用して変数を呼び出そうとしました。ただし、これはString、Array、およびArrayListデータ型では機能しません。
どうすればこれを行うことができますか?前もって感謝します。これが私のコードの言い換えです:
//main.cpp
bool LoadFileFromArgument = false; //A boolean can be declared global
String^ argument; //this will not pass from main.cpp to Form1.h
int main(array<System::String ^> ^args)
{
String ^ argument = args[1]
// 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 Form1());
return 0;
}
//Form1.h
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
extern bool LoadFileFromArgument; //is grabbed without error
extern String^ argument; //will not work
エラーは次のとおりです。
error C3145: 'argument' : global or static variable may not
have managed type 'System::String ^'
may not declare a global or static variable,
or a member of a native type that refers to objects in the gc heap