パラメータの変換に問題があります:
私はこの構造を持っています:
class XMLCO
{...};
class CO: public XMLCO
{...};
そして、私の問題はコンストラクターのこのクラスにあります。
class ProcessUnit
{
public:
ProcessUnit( const CO& co );
private:
NetComm _ipComm;
};
オブジェクト_ipComm(タイプNetComm)はXMLCOで初期化する必要がありますが、このコンストラクターではXMLCOを継承するCOのみが与えられるので、コンストラクターでそのようなダウンキャストを行うことができます。
ProcessUnit::ProcessUnit( const CO& co )
{
CO temp = const_cast<CO>( co ); // to remove the const -- THIS LINE CAUSE THE PROBLEM (it gives me this error: the type in a const_cast must be a pointer or reference to an object type
CO* ptrTemp = &temp; // to make it a pointer
XMLCO* xmlcc = dynamic_cast<IOXMLDescCreationContext*>( ptrTemp );
_ipComm = new IONetworkComm( *xmlcc );
}
私が知りたいのは、これを行うためのより簡単な方法があるかどうか(一般的な構造に何も変更せずに)、または私が何か間違ったことをしているのかどうかです。
ありがとう