I'm 开发者_StackOverflownoobie in c++. I have class DataBase which contains tables( class Table) and I must overload operators to get next result: dataBase(3,5)=someTable; - this code must replace tables 3-5 from database with table someTable.
So, help me please whith overload methods signatures.
The signature for overloading the function call operator within your DataBase
class is:
reference_type operator()( int first, int last );
Where reference_type
is a proxy reference, that is a helper type that stores a reference to the database and the first and last indexes, and overloads operator=
to do the replacement. Something in the lines of:
class proxy_reference
{
public:
proxy_reference( DataBase& database, int first, int last )
: _database( database )
, _first( first ), _last( last )
{}
--something-- operator=( Table const& someTable )
{
/* replace tables _first to _last from _database with someTable */
}
private:
DataBase& _database;
int _first, _last;
};
精彩评论