CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: learning c++

  1. #1
    Join Date
    Jul 2002
    Location
    singapore
    Posts
    10

    learning c++

    what is polymorphism? and what is operator overloading?
    what is difference between dll and lib? and how they are differenet and when to use which one?

  2. #2
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    Polymorphism:

    Polymorphism is the term used to describe the process by which different implementations of a function with the same name and the same number and the same types of input/output parameters can can be accessed for different objects. Polymorphism is achieved by overloading (re-writing) a function, either in a class hierarchy or for globally defined functions. There is the so-called compile-time polymorphism, for which the compiler can resolve the appropriate function to call at compile-time. There is also the so-called run-time polymorphism, for which the decision, which functinon to call will be made during program flow.

    Do not immediately associate polymorphism with operator overloading. Operator overloading is an example of compile-time polymorphism. Existing global operations (functions) such as +, -, *, /, etc., can be re-written (overloaded) such that the compiler is able to resolve the appropriate function to call at run-time.

    Run-time polymorphism arises in class hierarchies for which functions declared with the virtual modifier are overloaded in derived classes. See the code example below.

    The topic of lib, dll:
    A libraries (lib) is collection of existing, compiled codes which is statically linked to a program at the time of building the program. A dynamic link library (dll) is an existing collection of compiled codes which is loaded simultaneously loaded into the run-time environment of a program, providing run-time access to the compiled functions within the dll to the running program.

    Chris

    Code:
    #include <iostream>
    using namespace std;
    
    class A
    {
    public:
    
      virtual const void print(void) const
      {
        cout << "A" << endl;
      }
    };
    
    class B : public A
    {
    public:
    
      const void print(void) const
      {
        cout << "B" << endl;
      }
    };
    
    static void do_print_obj(const A& the_object)
    {
      the_object.print();
    }
    
    static void do_print_ptr(const A* p_object)
    {
      // Run-time polymorphism
      p_object->print();
    }
    
    int main(int argc, char* argv[])
    {
      A the_a;
      B the_b;
    
      do_print_obj(the_a);
      do_print_obj(the_b);
    
      do_print_ptr(&the_a);
      do_print_ptr(&the_b);
    
      return 1;
    }
    You're gonna go blind staring into that box all day.

  3. #3
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    Get a good introductory book such as "C++ from the Ground Up", Herbert Schildt

    http://www.amazon.com/exec/obidos/AS...646980-0930441

    Chris.
    You're gonna go blind staring into that box all day.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449
    Originally posted by dude_1967
    Get a good introductory book such as "C++ from the Ground Up", Herbert Schildt

    http://www.amazon.com/exec/obidos/AS...646980-0930441

    Chris.
    Here is a review of the book you mentioned by C++ peers:

    http://www.accu.org/cgi-bin/accu/rvo...file=cp001728a

    Schildt may write well, but beginners who want to get things done correctly should look elsewhere. Maybe "Accelerated C++" by Koenig & Moo:

    http://www.accu.org/cgi-bin/accu/rvo...&file=a002212a

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    In another post in this forum (see link below) other gurus pointed out some books which are probably much better than that one from Schildt.

    The C++ language is very powerful, offering the muscle to program in a terse, condensed and efficient fashion without compromising on expressiveness.

    http://www.codeguru.com/forum/showth...hreadid=199603

    Thanks, gurus.

    dude_1967
    You're gonna go blind staring into that box all day.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured