๐ŸŒˆ๋ช…ํ’ˆ C++ ํ”„๋กœ๊ทธ๋ž˜๋ฐ 6์žฅ๐Ÿง‘โ€๐Ÿ’ป

Se0ng_1lยท2022๋…„ 6์›” 22์ผ
0

๋ช…ํ’ˆCPPํ”„๋กœ๊ทธ๋ž˜๋ฐ

๋ชฉ๋ก ๋ณด๊ธฐ
6/10
post-thumbnail

6์žฅ ์š”์ 

ํ•จ์ˆ˜ ์ค‘๋ณต๊ณผ static๋ฉค๋ฒ„

ํ•จ์ˆ˜์ค‘๋ณต

ํ•จ์ˆ˜ ์ค‘๋ณต (๋‹คํ˜•์„ฑ)

๊ฐ™์€ ์ด๋ฆ„์˜ ํ•จ์ˆ˜๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.
์ด์ „๊ณผ์—์„œ ๋ฐฐ์šด ์ƒ์„ฑ์ž ํ•จ์ˆ˜๋„ ์ค‘๋ณต์ด๋‹ค.
์กฐ๊ฑด
1. ์ค‘๋ณต๋œ ํ•จ์ˆ˜๋“ค์˜ ์ด๋ฆ„์ด ๋™์ผ
2. ์ค‘๋ณต๋œ ํ•จ์ˆ˜๋“ค์˜ ๋งค๊ฐœ๋ณ€์ˆ˜ํƒ€์ž…์ด๋‚˜ ๊ฐœ์ˆ˜๊ฐ€ ์„œ๋กœ ๋‹ฌ๋ผ์•ผํ•œ๋‹ค.
3. ๋ฆฌํ„ดํƒ€์ž…์€ ๊ณ ๋ ค๋˜์ง€ ์•Š๋Š”๋‹ค.

์†Œ๋ฉธ์ž๋Š” ์˜ค์ง ํ•˜๋‚˜๋งŒ ์กด์žฌํ•˜๋ฏ€๋กœ ์ค‘๋ณต๋  ์ˆ˜ ์—†๋‹ค.

๋ฐฐ์—ด == ํฌ์ธํ„ฐ์ด๋ฏ€๋กœ ์ค‘๋ณต ๋ถˆ๊ฐ€๋Šฅ

๋””ํดํŠธ ๋งค๊ฐœ ๋ณ€์ˆ˜

๋งค๊ฐœ๋ณ€์ˆ˜์— ๊ธฐ๋ณธ๊ฐ’์„ ์ฃผ๋Š” ๊ฒƒ
ํด๋ž˜์Šค ๋ฉค๋ฒ„ํ•จ์ˆ˜๋ฅผ ํด๋ž˜์Šค ๋‚ด์—์„œ ์ •์˜ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ
์ •์˜ ๋ถ€๋ถ„์—์„œ ๋งค๊ฐœ๋ณ€์ˆ˜์— ๊ฐ’์„ ๋„ฃ๊ณ 
ํด๋ž˜์Šค ๋ฐ–์—์„œ ์ •์˜ํ•  ๋•Œ๋Š” ๊ฐ’์„ ๋„ฃ์ง€ ์•Š๋Š”๋‹ค.

int sum(int a = 3, int b = 5){return a + b};
// ํ•จ์ˆ˜ ์‚ฌ์šฉ์‹œ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋„ฃ์–ด์ฃผ์ง€ ์•Š์œผ๋ฉด a = 3, b = 5๊ฐ€ 
// ์ž๋™์œผ๋กœ ๋“ค์–ด๊ฐ€ 8์„ ๋ฆฌํ„ดํ•œ๋‹ค.

ย 
์กฐ๊ฑด
๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋์— ๋ชฐ๋ ค์žˆ์–ด์•ผํ•œ๋‹ค.

int sum(int a, int b = 5) (o)
int sum(int a = 3, int b) (x)

ํ•จ์ˆ˜ ์‚ฌ์šฉ์‹œ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ์•ž์—์„œ๋ถ€ํ„ฐ ์ฐจ๋ก€๋Œ€๋กœ ์ „๋‹ฌ๋œ๋‹ค.

sum(2); // a = 2 b = 5
sum(2, 3); // a = 2 b = 3

ํ•จ์ˆ˜ ์ค‘๋ณต ๊ฐ„์†Œํ™”
์ƒ์„ฑ์ž ์˜ˆ์‹œ)

Shape(){name = "๋„ค๋ชจ";}
shape(string name){this->name = name;}

๊ฐ„์†Œํ™”

shape(string name = "๋„ค๋ชจ"){this->name = name;}

ย 
๋งค๊ฐœ๋ณ€์ˆ˜์— ๊ธฐ๋ณธ๊ฐ’์ด ์žˆ๋‹ค๊ณ  ํ•จ์ˆ˜ ์ค‘๋ณต์„ ํ•  ์ˆ˜๋Š” ์—†๋‹ค.

ํ•จ์ˆ˜ ์ค‘๋ณต์˜ ๋ชจํ˜ธ์„ฑ

์›์ธ
ํ˜• ๋ณ€ํ™˜, ์ฐธ์กฐ ๋งค๊ฐœ ๋ณ€์ˆ˜, ๋””ํดํŠธ ๋งค๊ฐœ ๋ณ€์ˆ˜

ํ˜•๋ณ€ํ™˜

double foo(double a);
float foo(float a);
foo(4); // double๋กœ ํ• ์ง€ float๋กœ ํ• ์ง€ ๋ชจํ˜ธ์„ฑ ๋ฐœ์ƒ

์ฐธ์กฐ๋งค๊ฐœ๋ณ€์ˆ˜
ํ•จ์ˆ˜ ์‚ฌ์šฉ์‹œ ์–ด๋–ค๊ฑธ ์จ์•ผํ• ์ง€ ๋ชจํ˜ธ์„ฑ ๋ฐœ์ƒ

int foo(int a, int b){
    return a + b;
}
int foo(int a, int &b){
    return a + b;
}

๋””ํดํŠธ ๋งค๊ฐœ ๋ณ€์ˆ˜
ํ•จ์ˆ˜ ์‚ฌ์šฉ์‹œ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ํ•˜๋‚˜๋ฅผ ์ฃผ์—ˆ๋‹ค๋ฉด ์–ด๋–ค๊ฑธ ์จ์•ผํ• ์ง€ ๋ชจํ˜ธ์„ฑ ๋ฐœ์ƒ

void foo(int a);
void foo(int a, string b = "1234");

static๋ฉค๋ฒ„

static ๋ฉค๋ฒ„

ํด๋ž˜์Šค์—์„œ ๋ฉค๋ฒ„๊ฐ€ static์˜ ํŠน์„ฑ์„ ๊ฐ€์ง„๋‹ค.
ํŠน์„ฑ
1. ํ”„๋กœ๊ทธ๋žจ ์‹œ์ž‘ํ•  ๋•Œ ์ƒ์„ฑ๋˜๊ณ  ๋๋‚  ๋•Œ ์†Œ๋ฉธ
2. ์„ ์–ธ๋œ ๋ฒ”์œ„ ๋‚ด์—์„œ ์ „์—ญ์œผ๋กœ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

ํด๋ž˜์Šค์—์„œ staticํŠน์„ฑ
ํด๋ž˜์Šค ๋‚ด์—์„œ static๋ฉค๋ฒ„ ๋ณ€์ˆ˜๋Š” ์ดˆ๊ธฐํ™”๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.
ํด๋ž˜์Šค๊ฐ„์˜ ๊ณต์œ ๋ฅผ ์œ„ํ•ด ๊ฐ์ฒด๋‚ด๋ถ€ ๊ณต๊ฐ„์ด ์•„๋‹Œ ๋ณ„๋„์˜ ๊ณต๊ฐ„์— ์ €์žฅ
static๋ฉค๋ฒ„ ํ•จ์ˆ˜๋Š” static๋ฉค๋ฒ„ ๋ณ€์ˆ˜๋งŒ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
static๋ฉค๋ฒ„ ํ•จ์ˆ˜๋Š” this๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค.
(๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋˜๊ธฐ ์ „์— ์ด๋ฏธ ์„ ์–ธ๋˜๋ฏ€๋กœ)

์„ ์–ธ ๋ฐ ์ •์˜

static ๋ฉค๋ฒ„ ๋ณ€์ˆ˜;
static ๋ฉค๋ฒ„ ํ•จ์ˆ˜(){};

์‚ฌ์šฉ
์ผ๋ฐ˜์ ์ธ ๋ฉค๋ฒ„ ํ•จ์ˆ˜๋‚˜ ๋ฉค๋ฒ„ ๋ณ€์ˆ˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๋ฉด๋œ๋‹ค.
ํ•˜์ง€๋งŒ, ๊ฐ์ฒด๋ฅผ ํ†ตํ•˜์ง€ ์•Š์•„๋„ ํด๋ž˜์Šค ์ด๋ฆ„์œผ๋กœ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์ง€ ์•Š์•„๋„ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ด ๋ฐ”๋กœ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅ!

Shape::name = "์‚ผ๊ฐํ˜•";

๋ช…ํ’ˆ C++ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑ…
https://book.naver.com/bookdb/book_detail.naver?bid=13395206

โš ๏ธ ์ฃผ์˜ โš ๏ธ
1. ์—ฌ๊ธฐ์„œ๋ถ€ํ„ฐ๋Š” ์‹ค์Šต๋ฌธ์ œ ์ •๋‹ต์ž…๋‹ˆ๋‹ค.
2.์ œ๊ฐ€ ์ž‘์„ฑํ•œ ์ •๋‹ต์ด ํ‹€๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ˜น์‹œ ํ‹€๋ฆฐ๊ฒŒ ์žˆ๋‹ค๋ฉด ๋Œ“๊ธ€๋กœ ๋‚จ๊ฒจ์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํžˆ ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
3. C++๋ฅผ ๊ณต๋ถ€ํ•˜์‹œ๋Š” ํ•™์ƒ์ด์‹œ๋ผ๋ฉด ๋ณด์‹œ๊ธฐ ์ „์— ์ง์ ‘ ๊ผญ ํ•œ ๋ฒˆ ํ’€์–ด๋ณด์„ธ์š”!

์‹ค์Šต ๋ฌธ์ œ 6 - 1
๋ฌธ์ œ : ํ•จ์ˆ˜ ์ค‘๋ณต์œผ๋กœ addํ•จ์ˆ˜ ๊ตฌํ˜„ํ•˜๊ธฐ

#include <iostream>
using namespace std;
int add(int *a, int b)
{
    int sum = 0;
    for(int i = 0; i < b; i++)
    {
        sum += (*a + i);
    }
    return sum;
}

int add(int *a, int b, int *c)
{
    int sum = 0;
    for(int i = 0; i < b; i++)
    {
        sum += (*a + i) + (*c + i);
    }
    return sum;
}

int add(int *a, int *b, int c = 5)
{
    int sum = 0;
    for(int i = 0; i < c; i++)
    {
        sum += (*a + i) + (*b + i);
    }
    return sum;
}
int main()
{
    int a[] = {1, 2, 3, 4, 5};
    int b[] = {6, 7, 8, 9,  10};

    int c = add(a, 5);
    int d = add(a, 5, b);
    cout << c << endl;
    cout << d << endl;
    int e = add(a, b);
    cout << e << endl;
}

์‹ค์Šต ๋ฌธ์ œ 6 - 2
๋ฌธ์ œ : ํ•จ์ˆ˜ ์ค‘๋ณต์œผ๋กœ ์ƒ์„ฑ์ž ํ•จ์ˆ˜ ๊ตฌํ˜„ํ•˜๊ธฐ

#include <iostream>
#include <string>
using namespace std;

class Person{
    int id;
    double weight;
    string name;
public:
    /*
    Person(){
        id = 1;
        weight = 20.5;
        name = "grace";
    }
    Person(int id, string name){
        this->id = id;
        weight = 20.5;
        this->name = name;
    }
    Person(int id, string name, double weight){
        this->id = id;
        this->weight = weight;
        this->name = name;
    }
    */
    Person(int id = 1, string name = "grace", double weight = 20.5){
        this->id = id;
        this->weight = weight;
        this->name = name;
    }
    void show(){cout << id << ' ' << weight << ' ' << name << endl;}
};

int main()
{
    Person grace, ashley(2, "Ashley"), helen(3, "Helen", 32.5);
    grace.show();
    ashley.show();
    helen.show();
}

์‹ค์Šต ๋ฌธ์ œ 6 - 3
๋ฌธ์ œ : ํ•จ์ˆ˜ ์ค‘๋ณต์œผ๋กœ big()ํ•จ์ˆ˜ ๊ตฌํ˜„ํ•˜๊ธฐ

#include <iostream>
using namespace std;

/*
int big(int a, int b)
{
    int max = a > b ? a : b;
    return max > 100 ? 100 : max;
}
int big(int a, int b, int c)
{
    int max = a > b ? a : b;
    return max > c ? c : max;
}
*/
int big(int a, int b, int c = 100)
{
    int max = a > b ? a : b;
    return max > c ? c : max;
}

int main()
{
    int x = big(3, 5);
    int y = big(300, 60);
    int z = big(30, 60, 50);
    cout << x << ' ' << y << ' ' << z << endl;
}

์‹ค์Šต ๋ฌธ์ œ 6 - 4
๋ฌธ์ œ : ์ค‘๋ณต ์ƒ์„ฑ์ž ํ•˜๋‚˜์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๊ฐ€์ง„ ์ƒ์„ฑ์ž๋กœ ๋ฐ”๊พธ๊ธฐ

class MyVector{
    int *mem;
    int size;
public:
    /*
    MyVector();
    MyVector(int n, int val);
     */
    MyVector(int n = 0, int val = 0);
    ~MyVector() { delete [] mem;}

};
/*
MyVector::MyVector() {
    mem = new int[100];
    size = 100;
    for(int i = 0; i < size; i++) mem[i] = 0;
}
MyVector::MyVector(int n, int val) {
    mem = new int[n];
    size = n;
    for(int i = 0; i < size; i++) mem[i] = val;
}
 */
MyVector::MyVector(int n, int val) {
    mem = new int[n];
    size = n;
    for(int i = 0; i < size; i++) mem[i] = val;
}

์‹ค์Šต ๋ฌธ์ œ 6 - 5
๋ฌธ์ œ : ์ถœ๋ ฅ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋„๋ก 2๊ฐœ์˜ static๋ฉค๋ฒ„ํ•จ์ˆ˜๋ฅผ ์ง€๋‹Œ ArrayUtility ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ๊ตฌํ˜„ํ•˜๊ธฐ

#include <iostream>
using namespace std;

class ArrayUtility{
public:
    static void intToDouble(int source[], double dest[], int size){
        for(int i = 0; i < size; i++)
        {
            dest[i] = double(source[i]);
        }
    }
    static void doubleToInt(double source[], int dest[], int size){
        for(int i = 0; i < size; i++)
        {
            dest[i] = int(source[i]);
        }
    }
};

int main()
{
    int x[] = {1, 2, 3, 4, 5};
    double y[5];
    double z[] = {9.9, 8.8, 7.7, 6.6, 5.5};

    ArrayUtility::intToDouble(x, y,5);
    for(int i = 0; i < 5; i++) cout << y[i] << ' ';
    cout << endl;

    ArrayUtility::doubleToInt(z, x, 5);
    for(int i = 0; i < 5; i++) cout << x[i] << ' ';
    cout << endl;
}

์‹ค์Šต ๋ฌธ์ œ 6 - 6
๋ฌธ์ œ : ์ถœ๋ ฅ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋„๋ก 2๊ฐœ์˜ static๋ฉค๋ฒ„ํ•จ์ˆ˜๋ฅผ ์ง€๋‹Œ ArrayUtility2 ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ๊ตฌํ˜„ํ•˜๊ธฐ

#include <iostream>
using namespace std;

class ArrayUtility2{
public:
    static int* concat(int s1[], int s2[], int size){

        int *p = new int[size];
        cout << "ํ•ฉ์นœ ์ •์ˆ˜ ๋ฐฐ์—ด์„ ์ถœ๋ ฅํ•œ๋‹ค" << endl;
        for(int i = 0; i < 10; i++)
        {
            if(i < 5)
                p[i] = s1[i];
            else if(i >= 5)
                p[i] = s2[i - 5];
        }
        return p;
    }
    static int* remove(int s1[], int s2[], int size, int& retsize){
        cout << "๋ฐฐ์—ด x[]์—์„œ y[]๋ฅผ ๋บ€ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ";
        int *p = new int[size];
        int idx = 0;
        for(int i = 0; i < size; i++)
        {
            for(int j = 0; j < size; j++)
            {
                if(s1[i] == s2[j])
                {
                    retsize--;
                    break;
                }
                if(j == 4)
                {
                    p[idx++] = s1[i];
                }
            }
        }
        return retsize != 0 ? p : nullptr;
    }
};

int main()
{
    int x[5];
    int y[5];
    cout << "์ •์ˆ˜๋ฅผ 5 ๊ฐœ ์ž…๋ ฅํ•˜๋ผ. ๋ฐฐ์—ด x์— ์‚ฝ์ž…ํ•œ๋‹ค>>";
    for(int i = 0; i < 5; i++)
    {
        cin >> x[i];
    }
    cout << "์ •์ˆ˜๋ฅผ 5 ๊ฐœ ์ž…๋ ฅํ•˜๋ผ. ๋ฐฐ์—ด y์— ์‚ฝ์ž…ํ•œ๋‹ค>>";
    for(int i = 0; i < 5; i++) {
        cin >> y[i];
    }
    int *p = new int[10];
    p = ArrayUtility2::concat(x, y, 10);
    for(int i = 0; i < 10; i++)
        cout << p[i] << ' ';
    cout << endl;
    int retsize = 5;
    p = ArrayUtility2::remove(x, y, 5, retsize);
    cout << "๊ฐœ์ˆ˜๋Š” " << retsize << endl;
    for(int i = 0; i < retsize; i++)
        cout << p[i] << ' ';
    cout << endl;
    delete [] p;
}

์‹ค์Šต ๋ฌธ์ œ 6 - 7
๋ฌธ์ œ : static๋ฉค๋ฒ„๋ฅผ ์ง€๋‹Œ Randomํด๋ž˜์Šค ์™„์„ฑํ•˜๊ธฐ

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <random>
using namespace std;

class Random{
public:
    static void seed(){srand((unsigned)time(0));}
    static int nextInt(int min = 0, int max = 32767){
        return rand() % max + min;
    }
    static char nextAlphabet(){
        int n = rand() % 2;
        int a = rand() % 26 + 65;
        return char(32 * n + a);
    }
    static double nextDouble(){
        return double(rand()) / (double)RAND_MAX;
    }
};
int main()
{
    Random::seed();
    cout << "1์—์„œ 100๊นŒ์ง€ ๋žœ๋คํ•œ ์ •์ˆ˜ 10๊ฐœ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค" << endl;
    for(int i = 0; i <10; i++)
    {
        cout << Random::nextInt(1, 100) << ' ';
    }
    cout << endl;
    cout << "์•ŒํŒŒ๋ฒณ์„ ๋žœ๋คํ•˜๊ฒŒ 10๊ฐœ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค" << endl;
    for(int i = 0; i <10; i++)
    {
        cout << Random::nextAlphabet() << ' ';
    }
    cout << endl;
    cout << "๋žœ๋คํ•œ ์‹ค์ˆ˜๋ฅผ 10๊ฐœ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค" << endl;
    for(int i = 0; i <10; i++)
    {
        if(i == 5)
            cout << endl;
        cout << Random::nextDouble() << ' ';
    }
}

์‹ค์Šต ๋ฌธ์ œ 6 - 8
๋ฌธ์ œ : ๋””๋ฒ„๊น…์œ„ํ•œ Traceํด๋ž˜์Šค ์™„์„ฑํ•˜๊ธฐ

#include <iostream>
#include <cstring>
#include <string>
using namespace std;

class Trace{
    static int index;
    static char texts[100][100];
public :
    static void put(string func, string text){
        string temp = func + ":" + text;
        strcpy(texts[index], temp.c_str());
        index++;
    }
    static void print(string func = "main()"){
        if(func == "main()")
        {
            cout << "----- ๋ชจ๋“  Trace ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. -----" << endl;
            for(int i = 0; i < index; i++)
            {
                cout << texts[i] << endl;
            }
        }
        else
        {
            cout << "----- "<< func << "ํƒœ๊ทธ์˜ Trace ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. -----" << endl;
            for(int i = 0; i < index; i++)
            {
                char temp[100];
                strcpy(temp, texts[i]);
                if(func == strtok(temp, ":"))
                {
                    cout << texts[i] << endl;
                }
            }
        }
    }
};

int Trace::index = 0;
char Trace::texts[100][100] = {NULL,};

void f(){
    int a, b, c;
    cout << "๋‘ ๊ฐœ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”>>";
    cin >> a >> b;
    Trace::put("f()", "์ •์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›์•˜์Œ");
    c = a + b;
    Trace::put("f()", "ํ•ฉ ๊ณ„์‚ฐ");
    cout << "ํ•ฉ์€ " << c << endl;
}

int main()
{
    Trace::put("main()", "ํ”„๋กœ๊ทธ๋žจ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค");
    f();
    Trace::put("main()", "์ข…๋ฃŒ");

    Trace::print("f()");
    Trace::print();
}

์‹ค์Šต ๋ฌธ์ œ 6 - 9
๋ฌธ์ œ : ๊ฒŒ์‹œํŒ ๊ธฐ๋Šฅ Boardํด๋ž˜์Šค ์™„์„ฑํ•˜๊ธฐ

#include <iostream>
#include <string>
using namespace std;

class Board{
    static string boards[100];
    static int index;
public:
    static void add(string text)
    {
        boards[index++] = text;
    }
    static void print(){
        cout << "************* ๊ฒŒ์‹œํŒ์ž…๋‹ˆ๋‹ค. *************" << endl;
        for(int i = 0; i < index; i++)
        {
            cout << i + 1 << ": " << boards[i] << endl;
        }
        cout << endl;
    }
};
int Board::index = 0;
string Board::boards[100] = {};

int main()
{
    Board::add("์ค‘๊ฐ„๊ณ ์‚ฌ๋Š” ๊ฐ๋… ์—†๋Š” ์ž์œจ ์‹œํ—˜์ž…๋‹ˆ๋‹ค.");
    Board::add("์ฝ”๋”ฉ ๋ผ์šด์ง€ ๋งŽ์ด ์ด์šฉํ•ด ์ฃผ์„ธ์š”.");
    Board::print();
    Board::add("์ง„์†Œ๋ฆฐ ํ•™์ƒ์ด ๊ฒฝ์ง„๋Œ€ํšŒ ์ž…์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ถ•ํ•˜ํ•ด์ฃผ์„ธ์š”");
    Board::print();
}
profile
์น˜ํƒ€๊ฐ€ ๋˜๊ณ  ์‹ถ์€ ์ทจ์ค€์ƒ

0๊ฐœ์˜ ๋Œ“๊ธ€