リファレンスクラスは、コンパイラがクラッシュする(ただし、関数内で動作します)、現在
class commandsListClass
{
public:
std::string name;
std::string description;
std::vector<std::string> commands;
columnHeaders headersRequired;
void (*function)(System::Object ^);
std::string recoveryFileHeader;
void reset()
{
name = "";
description = "";
commands.clear();
headersRequired.reset();
recoveryFileHeader = "";
function = dummyFunc; // dummyFunc uses the same members as the intended - this is to ensure it is defined. DummyFunc is empty, returns void etc
}
commandsListClass()
{
reset();
}
};
私は以下のコードを実行した場合、コンパイラは
// This crashes the compiler
System::Threading::ThreadPool::QueueUserWorkItem(gcnew System::Threading::WaitCallback(global::commandsList[index].function), ti);
をクラッシュ
1>------ Build started: Project: MyProject, Configuration: Release x64 ------
1> project.cpp
1>c:\users\guy\documents\visual studio 2012\projects\MyProject\MyProject\Form1.h(807): fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'msc1.cpp', line 1443)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
私が呼び出しているのと同じ関数内のメンバーを宣言し、それは、グローバル:: commandsList [インデックス] .functionに、それはコンパイルし、正しく
// This runs correctly
void (*func)(System::Object ^);
func = global::commandsList[index].function;
System::Threading::ThreadPool::QueueUserWorkItem(gcnew System::Threading::WaitCallback(func), ti);
グローバルを実行します:: commandsListは、任意のアイデアタイプcommandsListClass
のベクトルのですか?ブラウジングGoogleとは、最適化しないようにコンパイラを変更することをお勧めします。これは成功していませんでした。コードはこのように書かれている:
インデックスは関数の変数があることが保証され-
作成時にdummyFuncに設定するか、コード内の別の場所に設定して正しい(要求された)関数に設定します。
ご協力いただければ幸いです。
編集1:これは、Visual Studio 2012を使用している、ここでのWindows 7のx64
私の提案は、関数ポインタの代わりに 'gcroot'を格納することです。 –