我有一個通過引用傳遞的另一個對象構造的對象。這是傳遞給構造函數的對象看起來是這樣的:檢查指向自定義類的指針是否不再存在
HTTPServerResponse::HTTPServerResponse(Poco::Net::HTTPServerResponse &response)
我的包裝類(HTTPServerResponse
)毀壞response
在某些時候,但它不也毀滅自己。實際上,有多種(外部)原因可能導致response
被破壞,即使是在我的課外。
我想要的是在調用response
的任何其他方法之前檢查它的存在。
我嘗試:
if(!response) {...
它生產error C2675: unary '!' : 'Poco::Net::HTTPServerResponse' does not define this operator or a conversion to a type acceptable to the predefined operator
;當然,我也試過:
if(response) {...
這也未能與error C2451: conditional expression of type 'Poco::Net::HTTPServerResponse' is illegal; No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
如何解決這個爛攤子?
請改用指針嗎? – Pubby
您無法知道對象是否被刪除/釋放。考慮做出更好的設計。 – Dani
@Pubby你能否提供一個例子作爲答案? –