2012년 12월 30일 일요일

[c++/class] 스왑함수를 클래스로

// CS.h
// --------------------------------
class CS{
public:
    void swap(int *x, int *y)
    {
        int temp;
        temp = *x;
        *x=*y;
        *y=temp;
    }
};

// cs.cpp
// ---------------------------------
#include <stdio.h>
#include "CS.h"

int main()
{
    int a=3, b=5;
    CS cs1;
        cs1.swap(&a,&b);
    printf("a=%d, b=%d\n", a, b);

    return 0;
}

댓글 없음:

댓글 쓰기