-
[C++_06_멤버의 접근 속성 클래스와 객체 만들기]c++ 2024. 10. 14. 16:50








#include <iostream>
using namespace std;
class Dog {
private:
int age;
public:
int getAge() {
return age;
}
void setAge(int a) { //a는 parameter
age = a;
}
};
int main()
{
Dog coco;
coco.setAge(14); //14는 argumentcout << coco.getAge();
return 0;
}
여기서 +, -는 접근 속성을 나타내는데, -는 private, +는 public를 의미한다.





class 다이어그램
Integer
______________
-val
_____________
+getVal()
+setVal()





함수를 class 내부에 정의 
함수를 class 외부에 정의 class 다이어그램
Man -age: int
-name: string
-weight: double+getName
+setName
+getAge
+setAge
+getWeight
+setWeight'c++' 카테고리의 다른 글
[C++]_08_const, new (0) 2024.11.04 [C++_07_객체와 멤버, 배열, 생성자, 소멸자, this] (0) 2024.10.28 [C++_05_객체지향언어_] (0) 2024.10.07 [C++]_04_함수 (0) 2024.09.30 [C++]_03_제어문, 함수 (0) 2024.09.23