Topic: ==" operator in C++
Author: clemens@server.informatik.uni-siegen.de (Clemens Wagner)
Date: 14 Apr 1994 07:25:33 GMT Raw View
In article <Co52nJ.vK@hkpu01.hkp.hk>, cs270196@hkpu01.hkp.hk (Yung Tin Ho) writes:
|> Ms. Yi Zheng (zhengyi@cs.ust.hk) wrote:
|> : Question
|> : --------
|>
|> : I cann't explain why the program produces,
|> :
|> : Callable_A : 22b20 == 22b20
|> : A_Callable : 22b90 == 22bf4
|> :
|> : rather than,
|> :
|> : Callable_A : 22b20 == 22b20
|> : A_Callable : 22b90 != 22bf4
|> :
|> :
|> : Program
|> : -------
|> :
|> : #include <stdio.h>
|> :
|> : class Callable {
|> : public:
|> : Callable() {}
|> : };
|> :
|> : class A {
|> : private:
|> : char padding[100];
|> : public:
|> : A() {};
|> : };
|> :
|> : class A_Callable : public A, public Callable {
|> : public:
|> : A_Callable() {};
|> : };
|> :
|> : class Callable_A : public Callable, public A {
|> : public:
|> : Callable_A() {};
|> : };
|> :
|> : int
|> : main()
|> : {
|> : Callable_A *ca = new Callable_A();
|> : A_Callable *ac = new A_Callable();
|> :
|> : Callable *c = (Callable*)ca;
|> : if (ca == c)
|> : printf("Callable_A : %x == %x\n", ca, c);
|> : else
|> : printf("Callable_A : %x != %x\n", ca, c);
|> :
|> : c = (Callable*)ac;
|> : if (ac == c)
|> : printf("A_Callable : %x == %x\n", ac, c);
|> : else
|> : printf("A_Callable : %x != %x\n", ac, c);
|> :
|> : return (0);
|> : }
|>
|> : ---------
|> : Thank you for your help.
|>
|> : Zheng Yi
|>
|> : zhengyi@jfleming.com
|>
|> In executing both "if (ca == c)" and "if (ac == c)", ca and ac
|> will be converted to type (Callable *). Therefore, they are
|> equal. But when you printf the pointers, no such convertion
|> is done so there values are different as it should be.
|>
|> you may refer to ARM on the implementation of multiple inheritance
|> where it is explained very clear.
|>
|> regards.
|> - thyung
|>
Sorry, in my opinion your are not right. The expressions ca == c and
ac == c compares POINTERS and NOT the dereference of this pointers.
The expressions are true, becase there are the statements
Callable *c = (Callable*)ca; and c = (Callable*)ca; before, respectively.
--
________________________________________________________________________________
Clemens Wagner With one wish we wake the will
Bergstr. 95 within wisdom.
With one will we wish the wisdom
50739 Koeln within waking.
Woken, wishing, willing.
0221 - 74 64 23 Dead can Dance
________________________________________________________________________________
e-mail: clemens@server.informatik.uni-siegen.de
GraphEd@server.informatik.uni-siegen.de (TinIV questions)
________________________________________________________________________________
Author: cs270196@hkpu01.hkp.hk (Yung Tin Ho)
Date: Tue, 12 Apr 1994 09:06:55 GMT Raw View
Ms. Yi Zheng (zhengyi@cs.ust.hk) wrote:
: Question
: --------
: I cann't explain why the program produces,
:
: Callable_A : 22b20 == 22b20
: A_Callable : 22b90 == 22bf4
:
: rather than,
:
: Callable_A : 22b20 == 22b20
: A_Callable : 22b90 != 22bf4
:
:
: Program
: -------
:
: #include <stdio.h>
:
: class Callable {
: public:
: Callable() {}
: };
:
: class A {
: private:
: char padding[100];
: public:
: A() {};
: };
:
: class A_Callable : public A, public Callable {
: public:
: A_Callable() {};
: };
:
: class Callable_A : public Callable, public A {
: public:
: Callable_A() {};
: };
:
: int
: main()
: {
: Callable_A *ca = new Callable_A();
: A_Callable *ac = new A_Callable();
:
: Callable *c = (Callable*)ca;
: if (ca == c)
: printf("Callable_A : %x == %x\n", ca, c);
: else
: printf("Callable_A : %x != %x\n", ca, c);
:
: c = (Callable*)ac;
: if (ac == c)
: printf("A_Callable : %x == %x\n", ac, c);
: else
: printf("A_Callable : %x != %x\n", ac, c);
:
: return (0);
: }
: ---------
: Thank you for your help.
: Zheng Yi
: zhengyi@jfleming.com
In executing both "if (ca == c)" and "if (ac == c)", ca and ac
will be converted to type (Callable *). Therefore, they are
equal. But when you printf the pointers, no such convertion
is done so there values are different as it should be.
you may refer to ARM on the implementation of multiple inheritance
where it is explained very clear.
regards.
- thyung
Author: zhengyi@cs.ust.hk (Ms. Yi Zheng)
Date: Fri, 25 Mar 1994 10:43:01 GMT Raw View
Question
--------
I cann't explain why the program produces,
Callable_A : 22b20 == 22b20
A_Callable : 22b90 == 22bf4
rather than,
Callable_A : 22b20 == 22b20
A_Callable : 22b90 != 22bf4
Program
-------
#include <stdio.h>
class Callable {
public:
Callable() {}
};
class A {
private:
char padding[100];
public:
A() {};
};
class A_Callable : public A, public Callable {
public:
A_Callable() {};
};
class Callable_A : public Callable, public A {
public:
Callable_A() {};
};
int
main()
{
Callable_A *ca = new Callable_A();
A_Callable *ac = new A_Callable();
Callable *c = (Callable*)ca;
if (ca == c)
printf("Callable_A : %x == %x\n", ca, c);
else
printf("Callable_A : %x != %x\n", ca, c);
c = (Callable*)ac;
if (ac == c)
printf("A_Callable : %x == %x\n", ac, c);
else
printf("A_Callable : %x != %x\n", ac, c);
return (0);
}
---------
Thank you for your help.
Zheng Yi
zhengyi@jfleming.com