开发者

c++ overload operators [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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;
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜