15
在方法GetValues()
使用互斥或以前拷貝構造dummy
實例後發佈?什麼因果關係 - 堆棧展開或返回值複製
class Protect
{};
class Test
{
public:
Protect GetValues() const;
private:
Protect m_protVal;
Mutex m_mutex;
};
Protect Test::GetValues() const
{
CLockGuard lock(m_mutex);
return m_protVal;
}
int main(int argc, char** argv)
{
Test myTestInstance;
Protect dummy = myTestInstance.GetValues();
}
假設CLockGuard
和Mutex
是具備升壓LIB標準類。
http://stackoverflow.com/questions/3856729/how-to -use-lock-guard-when-returning-protected-data – NPE
你可以在調試器中一步一步地運行你的測試程序(例如Linux上的'gdb')來查找。 –
@BasileStarynkevitch哪些人不會告訴他任何有關語言保證的內容。 –