cast operation

From: Onuchin Valeriy (onuchin@sirius.ihep.su)
Date: Fri Jul 23 1999 - 09:09:42 MEST


Dear C++ experts, I have few questions about cast operation.

problem:

class A 
{
 private:
    Object* theGoal;
 public:
    Object* GetTheGoal() const { return theGoal; }
 ...				
};

class B; // some other class

class C: public A, public B   // multiple inherited
{
 ...
};

B* d = new C();

// there are 2 choices to get pointer to theGoal

Object* goal1 = ((A*)d)->GetTheGoal();	// cast B to A
Object* goal2 = ((C*)d)->GetTheGoal();	// cast B to C


questions:

0. what cast from above is correct?
1. if there are rules to avoid segmentation violation errors?
2. what is difference between declarations
 	class C: public A, public B
and
  	class C: public B, public A
3. if cast operation is platform/compiler dependent ?		

 Excuse me for ignorrance.
 Thank in advance, with best  regards,      Valery



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:36 MET