const(FAQ)

Kevin Bealer kevinbealer at gmail.com
Sat Mar 29 00:22:40 PDT 2008


Kevin Bealer Wrote:

# int * GetValue(int key)
# {
#     int * p = (key in map);
#     if (p is null) {
#         map[key] = 0;
#         p = key in map;
#     }
#     return p;
# }
> 
> class SomeClass {
> public:
>     int serial = -1;
>     static int nextSerial = 1;
#
#     this() {
#         serial = ++nextSerial;
#     }
>     
>     int counter() const
>     {
>         int * p = GetValue(serial);
>         return ++*p;
>     }
> };
> 

[ Okay, I've fixed this a bit since it was clearly flawed, lines starting with # have changed. ]

Kevin






More information about the Digitalmars-d mailing list