在自身内部调用类函数/运算符 [英] Calling a class function/operator within itself

查看:66
本文介绍了在自身内部调用类函数/运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Heya,

对于研究图形编辑C ++项目,我需要一种定义和处理2D数组的简单方法.我添加了一个类,该类定义了大小为x * y的一维数组,但可以进行寻址并类似于二维数组.

Heya,

For a study graphics editing C++ project, I was in need of a simple way of defining and addressing 2D arrays. I added a class that defines a 1D array of the size x*y, but can be addressed and works similary to a 2D array.

Point* operator[](int x)
    {
        return & ARR[x * Y];
    }



通过使用operator方法,我可以轻松地从外部访问这些点.现在我的问题是,如何在类内部使用运算符.

例如,我想创建一个用于计算所有点的平均RGB值的类,但是如何在该类中使用运算符,该运算符的定义在?



With the use of the operator method, I can easily access the points from outside. Now my problem is, how do I use the operator from inside the class.

For example I want to create a class that calculates the avarage RGB value of all points, but how can I use the operator within the class, it was defined in?

推荐答案

我猜想这个(* this)[]可以.. ??
i guess this (*this)[] will do ..?


您也可以使用功能符号,例如
You may also use the function notation, e.g.
operator[](5);


这篇关于在自身内部调用类函数/运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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