Questionnaire ☑



Les prochaines questions font référence au code suivant :

class Toto
{
public:
    Toto(int v1)
        : _v4(_v3), _v1(v1), _v2(_v5)
    {
        _v3 = 3;
    }

private:
    int _v1 = 1;
    int _v2 = 2;
    int _v3;
    int _v4 = 4;
    int _v5 = 5;
}


class Dictionary
{
public:
    void add_definition(std::string word, std::string definition)
    {
        _definitions_by_words[word].emplace_back(definition);
    }

    std::vector<std::string> get_definitions(std::string word) const
    {
        return _definitions_by_words[word];
    }

    std::string get_first_definition(std::string word) const
    {
        auto it = _definitions_by_words.find(word);
        if (it != _definitions_by_words.end())
        {
            auto found_definitions = it->second;
            if (found_definitions.empty())
            {
                return found_definitions.front();
            }
        }

        auto default_value = std::string { "No definition found for " } + word;
        return default_value;
    }

private:
    std::map<std::string, std::vector<std::string>> _definitions_by_words;
};


Les prochaines questions concernent le code suivant :

struct Person
{
    std::string name;
};

struct Dog
{
    std::string name;
    Person& human
};

int main()
{
    auto jean = Person { "Jean" };
    auto attila = Dog { "Attila", jean };
    auto people = std::vector<Person*> { &jean, new Person { "Pierre" } };
    return 0;
}