본문 바로가기

프로그래밍/c++ /영상처리

연산자 오버로딩

반응형

#include <iostream>


using namespace std;

class Array {

int *arr;

int size;

int capacity;

public:

// 생성자

Array(int cap = 100) :arr(0), size(0), capacity(cap) {

arr = new int[capacity];

}

// 소멸자

~Array()

{

delete[] arr;

}


void Add(int data)

{

if (size < capacity)

{

arr[size++] = data;

}

}

int operator[] (int idx) const {

return arr[idx];

}

int Size() const {

return size;

}

};

int main()

{

Array test(10);

test.Add(1);

test.Add(13);

test.Add(21);


for (int i = 0; i < test.Size(); i++)

cout << test[i] << endl;

return 0;

}

반응형

'프로그래밍 > c++ /영상처리' 카테고리의 다른 글

SW-Maestro 첨부 2 목적지 건물찾기 앱  (0) 2016.05.17
STL- transform()  (0) 2016.05.11
영상의 회전 변환  (0) 2015.10.03
최근방 이웃 보간법  (0) 2015.10.03
영상이동  (0) 2015.10.02