Static Binding & Dynamic Binding :: C++

This is a discussion on Static Binding & Dynamic Binding :: C++ within the C++ Programming forums, part of the General Programming Boards category; Hi. Is there an advantage to using dynamic binding instead of static binding? I have both Deitel & Deitel C++ ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Static Binding & Dynamic Binding :: C++

    Hi.

    Is there an advantage to using dynamic binding instead of static binding?

    I have both Deitel & Deitel C++ How to Program and Stroustrup's Special Edition. I read all of the first book and finished chapter fifteen of Stroustrup. So I understand virtual functions and virtual base. However, I am not to the point where I can implement virtual functions and virtual base without asking: How do you implement them effectively?

    For example, "virtual" only works for pointer and reference. That is completely conceivable. However, it seems you have to declare an object of a derived class and then *cast* a new class from the base class to the derive class just to get it working right.

    -----------------
    classDerived cDerived = new classDerived;

    classBase *cBase = &cDerived;
    -----------------

    The example above comes straight from Deitel & Deitel. So everything looks okay. What is the point of declaring two separate classes? I understand that the use of "virtual," but I do not understand the performance of "virtual" if you have to declare an object of the derived class and an object of the base class. Under what specific situation do you implement dynamic binding? Please be very specific because I found that neither Deitel & Deitel nor Stroustrup give a convincing example of dynamic binding.

    Lastly, I too want to implement dynimic binding if it is possible to declare *one* object of either the base class or the derived class. The following is *not correct*:

    ------------------------
    classBase *cDynamic = new classDerived
    ------------------------

    In other words, *virtual* would be great if there is a way to use it without having to declare two seperate classes like the example from Deitel & Deitel.

    Thanks,
    Kuphryn

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    In response to your first [of many] questions, it really depends on the program. It'll become a sense on whether or not you should use dynamic binding after a while. There's not really a way to teach it.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 02:22 PM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 06:05 PM
  4. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  5. dynamic or static binding
    By noob2c in forum C++ Programming
    Replies: 1
    Last Post: 08-06-2003, 02:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21