class MySqlDbFactory: public DbDatabaseFactory{
public:
IConnection* CreateConnection(){
return new MySqlDbConnection();
}
ICommand* CreateCommand(){
return new MySqlDbCommand();
}
};
class Factory{
DbDatabaseFactory* _databaseFactory;
IConnection* _connection;
ICommand* _command;
public:
Factory(DbDatabaseFactory*);
void Start(){
_connection->Connect();
if(_connection->connectionState == true){
_command->Execute("SELECT ...");
}
};
};
Factory::Factory(DbDatabaseFactory* dbFactory)
{
_databaseFactory = dbFactory;
_connection = dbFactory->CreateConnection();
_command = dbFactory->CreateCommand();
}
int main(int argc, char *argv[])
{
MySqlDbFactory* mySQlFactory = new MySqlDbFactory();
Factory factory = new Factory(mySQlFactory); ...
我有错误
请求从
Factory*' to non-scalar type
工厂'转换 在
Factory factory = new Factory(mySQlFactory); line.
你有什么建议吗?
答案 0 :(得分:1)
这是:
Factory* factory = new Factory(mySQlFactory);
(请注意*
之后的Factory
)