covariant return type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I am new to .Net, ADO.Net and i have to programm an independent dataprovider
(no sql, no oledb, no odbc) and in addition it has to be in visual c++ :(
untill now i have two classes.
Class Conn derived from IDbConnection and class comm derived from idbcommand.

so my problem is the method 'Comm* CreateCommand' in class Conn, i allways
get the error message error C2392: ..... : Covariant-Returntype
WTF is that?????


__gc class Comm;
__gc class Conn : public IDbConnection
{
......
Comm* CreateCommand(){Comm* cmd = new Comm();
cmd->set_Connection(this);
return cmd;};
IDbCommand* IDbConnection::CreateCommand(){return this::CreateCommand();};
......
}


__gc class Comm : public IDbCommand
{
.......
}
 
My guess is that compiler generate the same signature for "Comm
*CreateCommand" method and "IDbConnection *CreateCommand". Probably because
Comm inherit from IDbConnection.
I don't understand why you need to have two public methods. May be you can
just rename "Comm *CreateCommand" method to "_CreateCommand".

Just one advice, I experienced the same project: I had to program a data
provider for a legacy data source. I'd choose to have two layers:
- a C++ managed layer in a DLL to call legacy data source
- a C# assembly to implement the ADO.NET provider interface and call my C++
layer.

I think it's simpler than mixed legacy call and ADO.NET interface.

Lionel.
 
Back
Top