bwells Posted April 13, 2003 Posted April 13, 2003 I have written an interface and a class that implements the interface. If I instantiate the class that implements the interface and then try and cast the class to be the type of the interface, I get a class cast exception. I am using __interface which I though is what the documentation suggested. Perhaps this is wrong? What is the difference between _interface, interface and __interface? When I use Intellisense in the debgger from the constructor of a class that implements the interface, it shows the interface as a struct. Is this correct? Here is my interface: #pragma once using namespace System; namespace COSP_9054_Interfaces { public __gc __interface ICOSP_9054_Connection { bool loadBoard( ); String* lastError( ); void* getConnection( ); }; } I stepped into the constructor and observed in the debugger that the class being constructed does indeed implement the interface. Yet if I do an explicit cast to the Interface type: ICOSP_9054_Connection* obj = (ICOSP_9054_Connection*) derivedClass; I get a class cast exception. I tried doing: dynamic_cast<ICOSP_9054_Connection*>(derivedClass) as well, but this just returns null. How come I cannot cast a derived class to be the type of the interface it implements? thanks Bryan Quote
Leaders quwiltw Posted April 13, 2003 Leaders Posted April 13, 2003 I must say I have no clue about C++ in .NET but have you used the __try_cast described in this article? Maybe since it's managed code it can't simply be casted the same? http://msdn.microsoft.com/msdnmag/issues/01/07/vsnet/default.aspx Then maybe you could at least catch the exception and see what it's complaining about. Quote --tim
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.