我正在使用這個項目使用指針,繼承和內部聚合(3的規則)。我理解3的規則的概念,並在這裏閱讀了幾篇關於它的文章。需要實施的基本原則是每個房間都有幾個會議(內部聚合)。客房具有以下屬性:C++ - 在下列情況下實現內部聚合
串d_name
INT d_nMeetings
會議** d_schedule。
我知道三個規則需要在Meeting ** d_schedule和d_schedule中實現,它是一個會議指針數組,它調用指向會議的指針數組。 但是我不太確定它在這種情況下的工作方式(在d_schedule中或在下面的函數中(在meeting.h中),它讀取void add(Meeting *))。以下是我的代碼:
會議.H:
#include <vector>
#include <string>
#include "item.h"
class Meeting: public Item{
protected:
bool d_coffee;
std::vector<std::string> d_participants;
public:
Meeting(std::string, Time, int, bool, std::vector<std::string>, int);
void print();
};
Meeting.cpp:
#include "meeting.h"
#include <iostream>
#include <string>
#include <vector>
#include "item.h"
Meeting::Meeting(std::string _what, Time _deadline, int _duration, bool _coffee, std::vector<std::string> _participants, int _priority = 0) : Item(_what, _deadline, _duration, priority = 0)
{
d_coffee = _coffee;
d_participants = _participants;
}
void Meeting::print()
{
Item::print();
}
Room.h:
#include "meeting.h"
class Room{
private:
std::string d_name;
Meeting** d_schedule;
int d_nMeetings;
public:
Room(std::string _name);
void setName(std::string);
std::string getName();
bool add(Meeting*);
void print();
};
謝謝