Thread: Polymorphism Theory Question - Polymorphic Class Definition.

  1. #1
    Registered User ventolin's Avatar
    Join Date
    Jan 2004
    Posts
    92

    Polymorphism Theory Question - Polymorphic Class Definition.

    Hi,

    I just want to settle an arguement between a fellow programmer and i.

    What is the exact definition of a Polymorphic Class?

    My interpretation is as so:

    A parametric polymorphic function is unbound if it contains a template parameter, where as it is bound if it countains a set number of determinable (during static linking) data types (eg overloaded functions in a class).

    Now a polymorphic class is a bound polymorphic class if it contains no parameter variables, and is simply a standard class.

    A polymorphic unbound class has a template parameter, denoting the polymorphic element of the class.

    This boils down to:
    Bound = known types, Unbound = Unknown types

    Bound Polymorphic Class = non-templated class.
    Unbound Polymorphic Class = templated class.

    I understand the need for the virtual function pointer inside a hierarchical class definintion, which is then used to perform the dynamic bind when attempting to resolve the correct virtual function call at run time - however a virtual function pointer along doesnt alone create polymorphism.

    However my knowledge of polymorphism boils down to the number of types used in a function (as per lambda calculus...?)

    My friend's defintion:

    A polymorphic class is a class which contains a virtual function pointer.

    He also believes that a Monomorphic class is a standard class.

    Is there such thing as a monomorphic class? From what i guess he means by this is a bound polymorphic class (from my interpretation).


    ---

    If im wrong on any points please bash me for being dumb, i just would like to resolve this arguement (even if im wrong!)



    Cheers,

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >What is the exact definition of a Polymorphic Class?
    Technically there isn't one. The standard makes no mention of polymorphism that I can recall.

    Polymorphism basically means many forms, so it stands to reason that any class which has many forms is polymorphic. Therefore, a template class is polymorphic, a class with virtual functions is polymorphic, even a class with overloaded member functions is polymorphic. Or you can make up your own interpretation, use someone else's, or whatever since the definition of OO concepts varies wildly depending on whom you ask.
    My best code is written with the delete key.

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by Prelude
    >What is the exact definition of a Polymorphic Class?
    Technically there isn't one. The standard makes no mention of polymorphism that I can recall.
    You know I have to check

    All sections are from ISO/IEC 14882:2003(E)
    1.8 1
    3.2 2
    5.2.7 6
    5.2.8 2 and 3
    10 5
    10.3 1
    12.6.2 9
    22.1.1 1

    of course those are all hits for polymorphic not polymorphism.
    From 10.3 1
    Virtual functions support dynamic binding and object-oriented programming. A class that declares or
    inherits a virtual function is called a polymorphic class.

  4. #4
    Registered User ventolin's Avatar
    Join Date
    Jan 2004
    Posts
    92
    Thanks Prelude - clears it up a little for me ! ill check out those standards thantos !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Question on polymorphism
    By 6tr6tr in forum C++ Programming
    Replies: 3
    Last Post: 05-06-2008, 09:05 AM
  3. class and pointer question
    By l2u in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2006, 10:00 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Class Definition?
    By Jamina in forum C++ Programming
    Replies: 4
    Last Post: 08-07-2003, 11:12 PM