-1
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
工廠」的錯誤C++:傳遞指針類參數的構造函數
轉換要求 上
Factory factory = new Factory(mySQlFactory); line.
你有什麼建議嗎?
編譯代碼謝謝你,但是當我打電話廠的啓動方法factory.Start();它說「開始」尚未宣佈。你有關於這個的建議嗎? – cagin
我會建議你採取一些基本的C++教程。答案是:factory-> Start();這是需要的,因爲factory是一個指向Factory對象的指針。 – cageman
在這種情況下,編寫MySqlDbFactory mySqlFactory就足夠了,不需要new。 (那麼你也可以省略dereference' - >') – erenon