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

« back to all changes in this revision

Viewing changes to yo/classes/memberinit.yo

  • Committer: Package Import Robot
  • Author(s): tony mancill, Frank B. Brokken, tony mancill
  • Date: 2012-02-28 00:50:21 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20120228005021-sz7nnodntkvgh7qf
Tags: 9.2.1-1
[ Frank B. Brokken ]
* New upstream release (using flexc++, reauthored polymorphic semantic
  values and unrestricted unions). Upstream release 9.2.0 is implied by
  this release.

[ tony mancill ]
* Set Standards-Version to 3.9.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
        static size_t s_nObjects;
18
18
 
19
19
        public:
20
 
            Container();    
 
20
            Container();
21
21
            Container(Container const &other);
22
22
            Container(Data *data, size_t size);
23
23
            Container(Container &&tmp);
24
24
    };
25
 
        ) 
 
25
        )
26
26
    The initial values of the data members are easy to describe, but somewhat
27
27
hard to implement. Consider the initial situation and assume the default
28
28
constructor is used: all data members should be set to 0, except for tt(d_nr)
47
47
initializers allow us to assign initial values to data members. The compiler
48
48
must be able to compute these initial values from initialization expressions,
49
49
but the initial values do not have to be constant expressions. So
50
 
tt(++s_nObjects) can be an initial value. 
 
50
tt(++s_nObjects) can be an initial value.
51
51
 
52
52
    Using data member initializers for the class tt(Container) we get:
53
53
        verb(
60
60
        static size_t s_nObjects;
61
61
 
62
62
        public:
63
 
            Container() = default;    
 
63
            Container() = default;
64
64
            Container(Container const &other);
65
65
            Container(Data *data, size_t size);
66
66
            Container(Container &&tmp);
67
67
    };
68
 
        ) 
 
68
        )
69
69
    Note that the data member initializations are recognized by the compiler,
70
70
and are applied to its implementation of the default constructor. In fact, all
71
71
constructors will apply the data member initializations, unless explicitly
72
72
initialized otherwise. E.g., the move-constructor may now be implented like
73
 
this: 
 
73
this:
74
74
        verb(
75
75
    Container(Container &&tmp)
76
76
    :