Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...