Click here to Skip to main content
15,915,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: a problem!!!! Pin
smartymanav28-Jun-05 21:02
smartymanav28-Jun-05 21:02 
GeneralRe: a problem!!!! Pin
toxcct29-Jun-05 0:15
toxcct29-Jun-05 0:15 
GeneralRe: a problem!!!! Pin
Cool Ju29-Jun-05 23:42
Cool Ju29-Jun-05 23:42 
GeneralRe: a problem!!!! Pin
smartymanav28-Jun-05 20:57
smartymanav28-Jun-05 20:57 
GeneralRe: a problem!!!! Pin
Christian Graus28-Jun-05 20:37
protectorChristian Graus28-Jun-05 20:37 
GeneralOperator= overloading Pin
Member 341989128-Jun-05 20:01
Member 341989128-Jun-05 20:01 
GeneralRe: Operator= overloading Pin
Christian Graus28-Jun-05 20:06
protectorChristian Graus28-Jun-05 20:06 
GeneralRe: Operator= overloading [edited - bis] Pin
toxcct28-Jun-05 20:23
toxcct28-Jun-05 20:23 
i don't understand you're problem...

you want to overload the operator=() for your class Test ?

nop, it's not actually what you want. here, you need an operator=() that returns an int. right ?
but what you can't do is reaching the (2,3) cell in your array.
so, you have to overload the operator()()...
<font color=blue>class</font> Test {
    <font color=blue>int</font> m_data[10][10];
 
  <font color=blue>public</font>:
    Test();
    <font color=blue>virtual </font>~Test();
    <font color=blue>void operator</font>=(<font color=blue>int</font>);    <font color=green>// not needed anymore</font>
    <font color=blue>int</font>& <font color=blue>operator</font>()(<font color=blue>int</font> x, <font color=blue>int</font> y);
};
 
<font color=blue>int</font>& Test::<font color=blue>operator</font>()(<font color=blue>int</font> x, <font color=blue>int</font> y) {
    <font color=green>// Tests if the indexes are in the ranges...</font>
    <font color=blue>if</font> (x <  0) x =  0;
    <font color=blue>if</font> (y <  0) y =  0;
    <font color=blue>if</font> (x > 10) x = 10;
    <font color=blue>if</font> (y < 10) y = 10;
    <font color=green>// Reaches the value...</font>
    <font color=blue>int</font>& ri = m_data[x][y];
    <font color=blue>return</font> ri;
}

this way, when you do:
Test tst;
tst(2, 3) <font color=green>// equivalent to tst.operator()(2, 3)</font>
  = 20;   <font color=green>// will use the standard operator=() working on integers</font>
ASSERT(tst(2,3) == 20);
 
Test *pTst = &tst;   <font color=green>// Pointer to tst</font>
(*pTst)(2, 3) = 21;  <font color=green>// Changes via a pointer the value of tst(2, 3)</font>
ASSERT(tst(2,3) == 21);


cheers,



TOXCCT >>> GEII power
[toxcct][VisualCalc]
GeneralRe: Operator= overloading Pin
Cedric Moonen28-Jun-05 20:31
Cedric Moonen28-Jun-05 20:31 
GeneralRe: Operator= overloading Pin
toxcct28-Jun-05 20:33
toxcct28-Jun-05 20:33 
GeneralRe: Operator= overloading Pin
Cedric Moonen28-Jun-05 20:37
Cedric Moonen28-Jun-05 20:37 
GeneralRe: Operator= overloading Pin
Member 341989129-Jun-05 3:52
Member 341989129-Jun-05 3:52 
GeneralRe: Operator= overloading Pin
toxcct29-Jun-05 6:30
toxcct29-Jun-05 6:30 
GeneralRe: Operator= overloading Pin
Member 341989129-Jun-05 19:33
Member 341989129-Jun-05 19:33 
GeneralRe: Operator= overloading Pin
toxcct29-Jun-05 20:11
toxcct29-Jun-05 20:11 
GeneralRe: Operator= overloading Pin
Member 341989129-Jun-05 23:12
Member 341989129-Jun-05 23:12 
GeneralRe: Operator= overloading Pin
toxcct30-Jun-05 0:11
toxcct30-Jun-05 0:11 
GeneralMFC controls. CListBox Pin
mpuerto28-Jun-05 18:28
mpuerto28-Jun-05 18:28 
GeneralRe: MFC controls. CListBox Pin
Christian Graus28-Jun-05 18:30
protectorChristian Graus28-Jun-05 18:30 
GeneralRe: MFC controls. CListBox Pin
mpuerto28-Jun-05 18:51
mpuerto28-Jun-05 18:51 
GeneralRe: MFC controls. CListBox Pin
Christian Graus28-Jun-05 19:03
protectorChristian Graus28-Jun-05 19:03 
GeneralRe: MFC controls. CListBox Pin
mpuerto28-Jun-05 19:19
mpuerto28-Jun-05 19:19 
GeneralRe: MFC controls. CListBox Pin
Christian Graus28-Jun-05 19:31
protectorChristian Graus28-Jun-05 19:31 
GeneralRe: MFC controls. CListBox Pin
Jose Lamas Rios29-Jun-05 2:54
Jose Lamas Rios29-Jun-05 2:54 
GeneralRe: MFC controls. CListBox Pin
mpuerto29-Jun-05 3:11
mpuerto29-Jun-05 3:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.