C++μμ κ°μ²΄λ₯Ό μμ±ν λ,
λμ μ°μ°μλ₯Ό μ¬μ©νμ§ μκ³ λ¦¬μ€νΈμ νμμΌλ‘ μ΄κΈ°ν νλ λ°©λ²μ΄ μ‘΄μ¬ν©λλ€.
μ΄λ₯Ό μ°λ¦¬λ μμ±μ μ΄κΈ°ν 리μ€νΈ λΌκ³ λΆλ¦ λλ€
μμλ₯Ό 보μ¬λλ¦¬κ² μ΅λλ€.
class Player {
private:
string name{};
int health{};
int xp{};
public:
// Constructor
Player(string name_val, int health_val, int xp_val);
};
Player::Player(string name_val, int health_val, int xp_val)
: name{name_val}, health{health_val}, xp{xp_val} {}
νμ§λ§ μ λ ₯νλ μ¬λμ΄ λͺ¨λ κ°μ μ λ ₯νμ§ μμ μ μκΈ° λλ¬Έμ μ°λ¦¬λ μ€λ²λ‘λ©μ ν©λλ€.
ν¨μμ μ€λ²λ‘λ©κ³Ό λμΌν κ°λ μ λλ€.
Player();
Player(string name_val);
Player(string name_val, int health_val);
Player(string name_val, int health_val, int xp_val);
Player::Player() : name{"None"}, health{0}, xp{0} {}
Player::Player(string name_val) : name{name_val}, health{0}, xp{0} {}
Player::Player(string name_val, int health_val)
: name{name_val}, health{health_val}, xp{0} {}
Player::Player(string name_val, int health_val, int xp_val)
: name{name_val}, health{health_val}, xp{xp_val} {}
νμ§λ§ λμΌν μ½λλ₯Ό μκΎΈ λ°λ³΅ν΄μ μ λ ₯νκ² λμ£ ?
μ΄λ₯Ό ν΄κ²°ν λ°©λ²μ λ€μκ³Ό κ°μ΅λλ€.
κ°μ₯ ν° λ²μμ μμ±μλ₯Ό λ¨Όμ μ§μ νκ³ , μ΄μ λμ νλ λ°©λ²μ λλ€.
Player(string name_val, int health_val, int xp_val);
Player();
Player(string name_val);
Player(string name_val, int health_val);
Player::Player(string name_val, int health_val, int xp_val)
: name{name_val}, health{health_val}, xp{xp_val} {}
Player::Player() : Player("None", 0, 0) {}
Player::Player(string name_val) : Player(name_val, 0, 0) {}
Player::Player(string name_val, int health_val): Player(name_val, health_val, 0) {}
'C++ > κ°μ²΄μ§ν₯ νλ‘κ·Έλλ° (OOP)' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[C++] ν΄λμ€ λ©€λ² μ κ·Ό μ νμ | Class Member Access Modifiers (1) | 2023.12.29 |
---|---|
[C++] ν¨μ νΉμ λ©μλμμ κ°μ²΄μ λΆνμν 볡μ¬λ₯Ό λ°©μ§νκΈ° (0) | 2023.12.29 |
[C++] ν€λκ°λ (header guards) | #pragma once, #ifndef (2) | 2023.12.28 |
[C++] ν΄λμ€ λ©€λ² μ κ·ΌνκΈ° (Accessing Class Members) (0) | 2023.12.26 |
[C++] ν΄λμ€μ κ°μ²΄ (0) | 2023.12.26 |