[英]C++ Builder 11.1.5 - Thread Class - All members are now private and not accessible outside of the thread
看着 RAD Studio 11.1.5 寫了一個小的 C++ Builder 測試程序使用線程。 我不斷收到如下編譯器錯誤:
// Execute routine of the TestThread
void __fastcall TTestThread::Execute()
{
int i,j,k;
bool MatrixOk;
long double Answer, ReadValue, SubDeterminant;
const HRESULT iniResult = CoInitializeEx(0, COINIT_MULTITHREADED);
if (!((iniResult == S_OK) || (iniResult == S_FALSE))) {
Application->MessageBox(L"Failed to initialize COM library.\n",L"Thread Error", MB_OK);
return;
}
// Place main part of thread here
while(!Terminated) {
Synchronize(UpdateDisplay);
Sleep(1000);
}
TheMessage = "Terminating... Cya";
Synchronize(ShowMessage);
CoUninitialize();
return;
}
void __fastcall TTestThread::UpdateDisplay()
{
Counter++;
MainForm->SB->SimpleText = "Counter: "+IntToStr(Counter);
MainForm->SB->Repaint();
return;
}
void __fastcall TMainModelThread::ShowMessage()
{
Application->MessageBox(TheMessage.w_str(),L"A Message", MB_OK);
return;
}
// Code that generates the errors below called from the main form OnClose event
MainModelThread->Terminate();
編譯錯誤信息如下:
[bcc64 Error] MainFrm.cpp(90): 'Terminate' is a private member of 'System::Classes::TThread'
MainFrm.h(17): constrained by implicitly private inheritance here
System.Classes.hpp(2726): member is declared here
[bcc64 Error] MainFrm.cpp(90): cannot cast 'TTestThread' to its private base class 'System::Classes::TThread'
MainFrm.h(17): implicitly declared private here
有其他人注意到這一點嗎? 此代碼將在 C++ Builder 10.3.1 下編譯。
您沒有顯示TTestThread
class 的聲明,但錯誤消息清楚地表明您正在使用(隱式) 私有inheritance從TThread
繼承,使TThread
的所有成員都是私有的,因此您的 ZA2F2ED4F8EBC2ABCBBB4Z2C 無法訪問。 您必須改用public inheritance ,例如:
class TTestThread : public TThread
^^^^^^
另外,僅供參考, Application->MessageBox()
不是線程安全的,因此必須同步。 您對它的第一次調用未同步,但您的第二次調用是同步的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.