class MyControl : public BaseControl
{
}
class Base
{
  proctected: 
    BaseControl &mControl;
}
class MyClass : public Base
{
  public:
    MyClass( MyControl &control );
    void ReadControl();
}
MyClass::MyClass( MyControl &control )
            :Base(control)
{
}
void MyClass::ReadControl( void )
{
  MyControl &control = (MyControl &)mControl;  // <=== ???
  control.DoSomething();
}

Hi all,
Can anyone tell me how to cast the BaseControl reference to a MyControl reference ?? The above code is basicly what I have.
Thanks in advance..

Make it a pointer instead of a reference.

Sorry but that is not an option...

if MyControl is a polymorphic type:

// ....
try
{
  MyControl& control = dynamic_cast<(MyControl&>( mControl ) ;
  control.DoSomething();
}
catch( const std::bad_cast& )
{
  // TODO: cast failed; handle it
}
// ...

if not:

// ....
  MyControl& control = static_cast<(MyControl&>( mControl ) ;
  // it is the programmer's (this means your) responsibility to make sure
  // that this cast is correct.
  control.DoSomething();
// ...

It was of the dynamic type !
vijayan121 thanks...

This question has already been answered. Start a new discussion instead.