~ubuntu-branches/ubuntu/trusty/c++-annotations/trusty

« back to all changes in this revision

Viewing changes to yo/concrete/polymorphic.yo

  • Committer: Package Import Robot
  • Author(s): Frank B. Brokken
  • Date: 2012-01-20 11:53:17 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20120120115317-v4wiq9sttx72fabk
Tags: 9.1.0-1
New upstream release (covering C++11 to a large extend)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Below the way Bisonc++ may use a polymorphic semantic value is described. The
2
 
described method is a direct result of a suggestion initially brought forward
3
 
by Dallas A. Clement in September 2007.
 
1
Bisonc++ may use polymorphic semantic values. How this is realized is covered
 
2
in this section. The described method is a direct result of a suggestion
 
3
initially brought forward by Dallas A. Clement in September 2007.
4
4
 
5
 
One may wonder why a tt(union) is still used by Bisonc++ as bf(C++) offers
 
5
One may wonder why tt(union)s are still used by Bisonc++, as bf(C++) offers
6
6
inherently superior constructs to combine multiple types into one type. The
7
 
bf(C++) way to combine types into one type is by defining a polymorphic base
8
 
class and a series of derived classes implementing the alternative data
9
 
types. Bisonc++ supports the tt(union) approach (and the unrestricted unions
10
 
with C++0x) for various (e.g., backward compatibility)
11
 
reasons. bi(Bison) and bi(bison++) both support the tt(%union) directive.
 
7
support by C++11 for unrestricted unions may result in tt(union)s being
 
8
re-evaluated, but bf(C++) traditionally offers a good alternative for the use
 
9
of tt(union)s: a polymorphic base class and a series of derived classes
 
10
implementing the alternative data types. 
12
11
 
13
 
An alternative to using a tt(union) is using a polymorphic base class. Such a
14
 
class is developed below (the class tt(Base)). As it is a polymorphic
15
 
base class it has the following characteristics:
 
12
Below, a polymorphic base class (the class tt(Base)) is developed. As it is a
 
13
polymorphic base class it has the following characteristics:
16
14
    itemization(
17
15
    it() Its destructor is virtual (and has a default implementation);
18
16
    it() Objects of the derived classes may be obtained from a