How can I solve ambiguity of base class properties?

  ambiguity, c++, inheritance

I am from the C# background. Therefore, I can’t understand how to solve this problem.

Let us look at the following class:

ProjectManager.hh

#ifndef INPUT_CPP_FILES_PROJECT_MANAGER_HH
#define INPUT_CPP_FILES_PROJECT_MANAGER_HH

#include <string>

#include "Employee.hh"
#include "Programmer.hh"
#include "Tester.hh"

namespace OrganizationNamespace {
    class ProjectManager : public Programmer, public Tester {
    public:
        ProjectManager() {}

        void print() const {
            std::cout << "(" << id_ << ", " << name_ << ", " << programming_language_ << "," << tool_ << ")"
                      << std::endl;
        }
    };
}
#endif //INPUT_CPP_FILES_PROJECT_MANAGER_HH

I have two questions in this regard:

  1. How can I implement parameterized and default constructors in ProjectManager by reusing base class constructors?
  2. How can I resolve ambiguity in the properties id_ and name_

I tried to write Employee::id_ and Employee::name_ that didn’t work.


Additional Source Code

Employee.hh

#ifndef INPUT_CPP_FILES_EMPLOYEE_HH
#define INPUT_CPP_FILES_EMPLOYEE_HH

#include <iostream>
#include <string>

namespace OrganizationNamespace {
    class Employee {
    protected:
        std::string id_;
        std::string name_;

    public:
        Employee() : id_ (""), name_("") {}

        Employee(const std::string &id) : id_(id), name_("") {}

        Employee(const std::string &id, const std::string &name) : id_(id), name_(name) {}

        Employee(Employee const & emp)
        {
            this->id_ = emp.id_;
            this->name_ = emp.name_;
        }

        void print() const
        {
            std::cout << "(" << id_ << ", " << name_ << ")" << std::endl;
        }
    };
}
#endif //INPUT_CPP_FILES_EMPLOYEE_HH

Programmer.hh

#ifndef INPUT_CPP_FILES_PROGRAMMER_HH
#define INPUT_CPP_FILES_PROGRAMMER_HH

#include "Employee.hh"

namespace OrganizationNamespace {
    class Programmer : public Employee {
    protected:
        std::string programming_language_;

    public:
        Programmer() : Employee(), programming_language_("") {}

        Programmer(std::string id) : Employee(id) {}

        Programmer(std::string id, std::string name) : Employee(id, name) {}

        Programmer(std::string id, std::string name, std::string programming_language) : Employee(id, name),
                                                                                         programming_language_(
                                                                                                 programming_language) {}

        void print() const {
            std::cout << "(" << id_ << ", " << name_ << ", " << programming_language_ << ")" << std::endl;
        }
    };
}

#endif //INPUT_CPP_FILES_PROGRAMMER_HH

Tester.hh

#ifndef INPUT_CPP_FILES_TESTER_HH
#define INPUT_CPP_FILES_TESTER_HH

#include <string>

#include "Employee.hh"

namespace OrganizationNamespace {

    class Tester : public Employee {
    protected:
        std::string tool_;

    public:
        Tester() : Employee(), tool_("") {}

        Tester(std::string id) : Employee(id) {}

        Tester(std::string id, std::string name) : Employee(id, name) {}

        Tester(std::string id, std::string name, std::string tool) : Employee(id, name), tool_(tool) {}

        void print() const {
            std::cout << "(" << id_ << ", " << name_ << ", " << tool_ << ")" << std::endl;
        }
    };
}
#endif //INPUT_CPP_FILES_TESTER_HH

Source: Windows Questions C++

LEAVE A COMMENT