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 :

class Person
{
public:    
    Person(const std::string& name) : _name{new std::string{name}} {}
    ~Person() { delete _name; }
    std::string* _name;
};

class Dog
{
public:
    Person(const std::string& name, Person& human) 
    : _name{new std::string{name}}
    , _owner{human}
    , _owner_name{human.name}
    {}
      
    std::string _name;
    Person& _owner
    std:string* _owner_name
};

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