473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

oveloading operators

Hello, I am trying to do the following:

....
int x;
clsIMG a;
a(10,40) = 40;
x = a(10,40);
.....

the source for my class:

class clsIMG
{
private:
UINT8 img[680][500];
public:
clsIMG(void);
~clsIMG(void);
UINT8 operator()(UINT8 x, UINT8 y);
};

UINT8 clsIMG::operator()(UINT8 x, UINT8 y)
{
return img[x][y];
}

The x = a(10,40) is ok! No problem, how I can do the
a(10,50) = 50;

Thanks
Arnaldo Giacomitti Junior.

Nov 25 '05 #1
2 1510
Arnaldo wrote:
Hello, I am trying to do the following:

...
int x;
clsIMG a;
a(10,40) = 40;
x = a(10,40);
....

the source for my class:

class clsIMG
{
private:
UINT8 img[680][500];
public:
clsIMG(void);
~clsIMG(void);
UINT8 operator()(UINT8 x, UINT8 y);
};

UINT8 clsIMG::operator()(UINT8 x, UINT8 y)
{
return img[x][y];
}

The x = a(10,40) is ok! No problem, how I can do the
a(10,50) = 50;


Instead of returning a *value* from operator(), return a *reference*.
(Look it up in whatever text you're using for your C++ explorations.)

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com (new post 8/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Nov 25 '05 #2
"Arnaldo" <gi********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com
Hello, I am trying to do the following:

...
int x;
clsIMG a;
a(10,40) = 40;
x = a(10,40);
....

the source for my class:

class clsIMG
{
private:
UINT8 img[680][500];
public:
clsIMG(void);
~clsIMG(void);
UINT8 operator()(UINT8 x, UINT8 y);
Make this one const, i.e.,

UINT8 operator()(UINT8 x, UINT8 y) const;

and declare a new non-const one returning a reference

UINT8 & operator()(UINT8 x, UINT8 y);
};

UINT8 clsIMG::operator()(UINT8 x, UINT8 y)
Change this to

UINT8 clsIMG::operator()(UINT8 x, UINT8 y) const
{
return img[x][y];
}
and define the second operator:

UINT8 & clsIMG::operator()(UINT8 x, UINT8 y)
{
return img[x][y];
}

The x = a(10,40) is ok! No problem, how I can do the
a(10,50) = 50;

--
John Carson
Nov 25 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: greg | last post by:
Discussion is invited on the following proto-PEP. ------------------------------------------------------------- PEP ??? - Overloadable Boolean Operators...
4
by: GianGuz | last post by:
Global new and delete operators can be overloaded to suite particulars needs. Typically they are overloaded to insert useful debugging/trace informations. What I would to discuss here concerns the...
6
by: bearophileHUGS | last post by:
Sometimes I suggest to add things to the language (like adding some set methods to dicts), but I've seen that I tend to forget the meaning of six set/frozenset operators: s & t s &= t s | t s...
6
by: jas_lx | last post by:
The basic understanding of what bitwise operators (& ^ | >> << ) comes fairly simple, as long as one has a fundamental understanding of bits, bytes and binary. Having done some Win32...
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
49
by: raju | last post by:
hi can we compare two integers without using relational operators (== != < <= > >=) thanks rajesh s
0
by: Syanide | last post by:
here's a bit info for you fellas: eg.. you have Square classes u wanna add public static int operator+ (Square s1, Square s2) { // your code here } comparision operators..
17
by: Steve R. Hastings | last post by:
I have been studying Python recently, and I read a comment on one web page that said something like "the people using Python for heavy math really wish they could define their own operators". The...
28
by: dspfun | last post by:
I'm trying to get a good understanding of how unary operators work and have some questions about the following test snippets. int *p; ~!&*++p--; It doesn't compile, why? The problem seems to be...
18
by: Zach | last post by:
Can someone list the various macro operators and what they mean. Came across a function macro: #define max(a, b) ((a)>(b)?(a):(b)) What does "?" amd ":" mean in this statement? Zach
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.