[合集] 也来一道面试题C++# Programming - 葵花宝典
c*d
1 楼
☆─────────────────────────────────────☆
hero (自古英雄出壮年) 于 (Thu Sep 6 23:38:37 2007) 提到:
说是有个class 叫 DataBase. user 不能通过创建来用它.否则n个用户就得辟n个
DataBase 的空间了,怎样让所有用户公用一个DataBase 空间?
我这样做对吗?
Class Database{
Private:
Static Database* b;
DataBase();
~DataBase();
Public:
Static Database getDB(){Return (b = new Database);};
}
and then user can call get DataBase in this way:
main(){
...
Database a = Database::getDB();
Database b = Database::getDB();
...
}
thereby a and b point to the same memory
hero (自古英雄出壮年) 于 (Thu Sep 6 23:38:37 2007) 提到:
说是有个class 叫 DataBase. user 不能通过创建来用它.否则n个用户就得辟n个
DataBase 的空间了,怎样让所有用户公用一个DataBase 空间?
我这样做对吗?
Class Database{
Private:
Static Database* b;
DataBase();
~DataBase();
Public:
Static Database getDB(){Return (b = new Database);};
}
and then user can call get DataBase in this way:
main(){
...
Database a = Database::getDB();
Database b = Database::getDB();
...
}
thereby a and b point to the same memory