C++ 객체 개수
![[C++] static member data](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FblbFUH%2FbtqzNBrmgit%2FBiJ7sDCaGy9PeBqdHuXNKK%2Fimg.png)
[C++] static member data
1. 정적 멤버 데이터 (static member data) #include class Car { int speed; int color; public: Car() {} ~Car() {} }; int main() { Car c1; Car c2; Car c3; } ① 객체의 생성과 소멸 => 모든 객체는 생성 될 때 생성자를 호출하고 => 모든 객체는 파괴 될 때 소멸자를 호출한다. ② 객체가 몇 개 생성되었는지 개수를 알고 싶다면 => 생성자에서 변수 값을 +1 => 소멸자에서 변수 값을 -1 ③ 객체의 개수를 관리할 변수가 필요하다. 객체의 개수를 관리할 변수를 만들어보자 #include class Car { int speed; int color; public: int cnt = 0; Car() { ++..