process
最初は何も割り当てずに呼び出されるグローバル変数を作成したいと考えています。後で、オペレーティング システムで新しいプロセスを生成し、その変数に割り当てます。
次のように C# で実行できます。
class TestCS
{
// creating a variable
private System.Diagnostics.Process process;
private void SomeMethod()
{
// assigning a newly spawned process to it
process = Process.Start("file.exe", "-argument");
process.WaitForInputIdle();
}
}
C++で同じことを達成するために、以下のコードを書きました。process
変数の型は( child
Boost ::Process v0.31 から) です。#includesは、簡単にするために省略されています。
Test.hpp
class Test
{
public:
void SomeFunction();
private:
std::string testString; // declaring a test string
static const std::string program_name;
static const std::vector<std::string> program_args;
boost::process::child process; // attempting to declare a variable of type 'boost::process::child'
};
テスト.cpp
void Test::SomeFunction()
{
testString = "abc"; // I can successfully define the test variable on this line
std::cout << testString;
boost::process::context ctxt;
// the same goes for the next two variables
const std::string program_name = "startme.exe";
const std::vector<std::string> program_args = {"/test"};
// and I want to define the process variable here as well...
process = boost::process::launch(program_name, program_args, ctxt);
}
メイン.cpp
int main()
{
Test test1;
test1.SomeFunction();
cin.get(); // pause
return 0;
}
ただし、Test.cppに対して次のエラーが返されます。
エラー C2512: 'boost::process::child': 適切な既定のコンストラクターがありません
どうすれば正しく行うことができますか?