-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMediator.cpp
45 lines (35 loc) · 878 Bytes
/
Mediator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//compile using g++ Mediator.cpp -Wc++11-extensions -std=c++11
#include <string>
#include <iostream>
#include <memory>
class User;
class ChatRoom {
public:
static void showMessage(User *user, const std::string &message);
};
class User {
private:
std::string name;
public :
std::string getName() {
return name;
}
void setName(const std::string &name) {
this->name = name;
}
User(const std::string &name){
this->name = name;
}
void sendMessage(const std::string &message){
ChatRoom::showMessage(this,message);
}
};
void ChatRoom::showMessage(User *user, const std::string &message){
std::cout<<" ["<<user->getName()<<"] : "<<message<<std::endl;
}
int main(){
User robert("Robert");
User john("John");
robert.sendMessage("Hi! join!");
john.sendMessage("Hellp! robert!");
}