#include <iostream>
#include <map>
using namespace std;
class Test
{
private:
Test** arr = new Test * [10];
map<int, Test**> m;
public:
int val = 0;
Test() { cout << "Instantiated!" << endl; }
Test(int val) : val(val) { }
~Test() { cout << "Deleted!" << endl; }
public:
void Init()
{
for (int i = 0; i < 10; i++)
arr[i] = new Test(i);
m[0] = arr;
}
void Release()
{
for (int i = 0; i < 10; i++)
delete arr[i];
delete[] arr;
}
void Set(int mIdx, int aIdx, int val = 0) { m[mIdx][aIdx]->val = val; }
int Get(int mIdx, int aIdx) { return m[mIdx][aIdx]->val; }
};
int main()
{
Test test;
test.Init();
cout << "Before val : " << test.Get(0, 0);
test.Set(0, 0, 7);
cout << "After val : " << test.Get(0, 0) << endl;
test.Release();
}
'프로그래밍 언어 > C++' 카테고리의 다른 글
[C] 문자열(String) - 문자열 저장, 널문자, 문자열 배열, 문자열 크기 (0) | 2023.08.31 |
---|---|
[C] 정적변수, 지역변수, 전역변수 비교 (static, local, global) (0) | 2023.08.28 |
C++ 참조자(Reference)의 이해 (0) | 2023.08.21 |
C Call-by-Value(값에 의한 호출) & Call-by-Reference(참조에 의한 호출)의 이해 (0) | 2023.08.21 |
[C++] 문자열 인코딩 (유니코드 멀티바이트 UTF-8 변환) (0) | 2023.08.10 |