Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- backend
- 백준
- frontend
- Project
- C++
- java
- Python
- 자바정리
- 자바독학
- 개발
- Reflex
- 개발자
- 개인프로젝트
- java정리
- 사물인터넷
- 이웃한 칸
- 풀스택프레임워크
- 코딩
- 주가예측
- 코테
- SNS
- 프로그램
- 코스닥
- 코딩독학
- 프로그래머스
- 모의 주식
- 자바
- 코딩테스트
- 프로그래밍
- 빅데이터
Archives
- Today
- Total
Creative Code
boundArray(index지정) 본문
※main.cpp파일
#include <iostream>
#include "boundArray.h"
int main() {
BoundArray arr1; //BoundArray arr1(0,10); [0,10)
BoundArray arr2(100); // BoundArray arr2(0,100); [0,100)
BoundArray arr3(1,11); // index[1,11)
for (int i = arr2.lower(); i<arr2.upper(); ++i) {
arr2[i] = i;
}
const BoundArray arr4 = arr3;
arr1 = arr3;
arr1 == arr3;
for (int i = arr2.lower(); i<arr2.upper(); ++i) {
std::cout << arr2[i] << " ";
}
std::cout << std::endl;
return 0;
}
※boundArray.h 파일
#ifndef BOUNDARRAY_H
#define BOUNDARRAY_H
#include "safeArray.h"
class BoundArray:public SafeArray {
private:
int low_;
protected:
public:
explicit BoundArray(int size= Array::getDefaultSize());
BoundArray(int low, int up);
virtual ~BoundArray(){}
bool operator==(const BoundArray&) const;
int lower();
int upper();
virtual int& operator[](int index);
virtual const int& operator[](int index) const;
};
#endif
※boundArray.cpp파일
#include "boundArray.h"
#include <cassert>
BoundArray::BoundArray(int size)
:low_(0),SafeArray(size)
{
}
BoundArray::BoundArray(int low, int up)
:low_(low),SafeArray(up-low)
{
}
bool BoundArray::operator==(const BoundArray& rhs) const {
return low_ == rhs.low_ && this->SafeArray::operator==((SafeArray)rhs);
}
int& BoundArray::operator[](int index) {
return this->SafeArray::operator[](index - low_);
}
const int& BoundArray::operator[](int index) const {
return this->SafeArray::operator[](index - low_);
}
int BoundArray::lower() {
return low_;
}
int BoundArray::upper() {
return low_ + this->Array::size();
}
'C++ Programming' 카테고리의 다른 글
stack4(template사용) (0) | 2023.09.08 |
---|---|
array2(template사용) (0) | 2023.09.08 |
shape(도형 상속) (0) | 2023.09.07 |
safeArray2(상속) (0) | 2023.09.07 |
queue3(array클래스와 has -a관계) (0) | 2023.09.06 |