google-code-export / cortex-vfx

Automatically exported from code.google.com/p/cortex-vfx
0 stars 0 forks source link

Ambiguity resolution for smart pointer casts #37

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The following code won't compile due to an ambiguity not resolved by  the smart 
pointer constructors. boost::intrusive_ptr deals with it by using this 
sp_enable_if_convertible magic. We should either do the same or revert to using 
boost::intrusive_ptr.

--------------------------------------------------------------------------

#include <IECore/RunTimeTyped.h>

namespace cit
{

// E subclasses A, D subclasses B
enum TypeId
{
    ATypeId = 701000,
    BTypeId,
    DTypeId,
    ETypeId
};

IE_CORE_FORWARDDECLARE( A );
class A : public IECore::RunTimeTyped
{
public:
    IE_CORE_DECLARERUNTIMETYPEDEXTENSION( A, ATypeId, RunTimeTyped );
};

IE_CORE_FORWARDDECLARE( B );
class B : public IECore::RunTimeTyped
{
public:
    IE_CORE_DECLARERUNTIMETYPEDEXTENSION( B, BTypeId, RunTimeTyped );   
};

IE_CORE_FORWARDDECLARE( D );
class D : public B
{
public:
    IE_CORE_DECLARERUNTIMETYPEDEXTENSION( D, DTypeId, B );
    D( BPtr b ) : _b(b) {}
    D( APtr a ) {}

    BPtr _b;
};

IE_CORE_FORWARDDECLARE( E );
class E : public A
{
public:
    IE_CORE_DECLARERUNTIMETYPEDEXTENSION( E, ETypeId, A );

};

}

int main( int, char**)
{
    cit::EPtr ep = new cit::E;
    cit::DPtr dp = new cit::D( ep );

    return 0;
}

Original issue reported on code.google.com by thehaddo...@gmail.com on 24 Nov 2010 at 3:29

GoogleCodeExporter commented 9 years ago

Original comment by andrewk....@gmail.com on 4 Dec 2010 at 12:39