C ++"this"和运算符重载 [英] C++ 'this' and operator overloading

查看:121
本文介绍了C ++"this"和运算符重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将运算符与"this"一起使用.举个例子:

I was wondering how can you use operators along with 'this'. To put an example:

class grd : clm
{ 
    inline int &operator()(int x, int y) { return g[x][y]; }
    /* blah blah blah */ 
};

grd grd::crop(int cx1, int cy1, int cx2, int cy2)
{
    grd ngrd(abs(cx1-cx2), abs(cy1-cy2));
    int i, j;
    //
    for (i = cx1; i < cx2; i++)
    {
        for (j = cy1; j < cy2; j++)
        {
            if (i >= 0 && i < x && j >= 0 && j < y)
                ngrd(i-cx1,j-cy2) = ?? // this->(i,j); ****
        }
    }
    return ngrd;
}

谢谢!

推荐答案

其中之一: this->operator()(i,j)(*this)(i,j)

这篇关于C ++"this"和运算符重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆