Поведение C ++ Object Reference

Рассмотрим следующий сегмент кода:

class Window // Base class for C++ virtual function example
     {
       public:
          virtual void Create() // virtual function for C++ virtual function example
          {
               cout <<"Base class Window"<<endl;
          }
     };

     class CommandButton : public Window
     {
       public:
          void Create()
          {
              cout<<"Derived class Command Button - Overridden C++ virtual function"<<endl;
          }
     };

     int main()
     {
        Window *button = new   CommandButton;
        Window& aRef = *button;
        aRef.Create(); // Output: Derived class Command Button - Overridden C++ virtual function
        Window bRef=*button;
        bRef.Create(); // Output: Base class Window

        return 0;
     }

Оба aRef и bRef получить назначенную кнопку * , но почему эти два вывода отличаются. What is the difference between assigning to Reference type and non Reference type?

5
задан Shamim Hafiz 24 December 2010 в 06:35
поделиться