728x90
간단한 static, class , operator문제.
class Message {
private:
string _msg;
static int _id;
int myId;
public:
Message() {}
Message(string msg) : _msg(msg) {
myId = _id++;
}
const string& get_text() {
return _msg;
}
int getMyId() {
return myId;
}
bool operator<(Message a)
{
return myId < a.myId;
}
};
int Message::_id = 0;
class MessageFactory {
public:
MessageFactory() {}
Message create_message(const string& text) {
Message *msg = new Message(text);
return *msg;
}
};
728x90
'개발 공부 > 알고리즘' 카테고리의 다른 글
HackerRank, c++, Magic Spells (1) | 2022.11.04 |
---|---|
HackerRank, C++, Accessing Inherited Functions (0) | 2022.11.04 |
HackerRank, c++, Overloading Ostream Operator (1) | 2022.11.03 |
HackerRank, C++, Overload Operators (0) | 2022.11.03 |
HackerRank, c++, Preprocessor Solution (0) | 2022.11.03 |