blob: 5e3c6e97887741bceeb90bce66dd845701764e81 [file] [log] [blame]
Brian Silvermanf3ec38b2022-07-06 20:43:36 -07001// Copyright 2022 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9#pragma once
10
11#include <cstdint>
12#include <sstream>
13#include <stdint.h>
14#include <string>
15
16class Goat {
17public:
18 Goat() : horns(0) {}
19 void add_a_horn();
20 std::string describe() const;
21private:
22 uint32_t horns;
23};
24
25
26inline void Goat::add_a_horn() { horns++; }
27inline std::string Goat::describe() const {
28 std::ostringstream oss;
29 std::string plural = horns == 1 ? "" : "s";
30 oss << "This goat has " << horns << " horn" << plural << ".";
31 return oss.str();
32}
33
34class Field {
35public:
36 const Goat& get_goat() const {
37 return the_goat;
38 }
39
40private:
41 Goat the_goat;
42};