✨언어/c++

2023.01.24#14-1 추가 확장 01. 추가 확장 저번에 했던 ch.13의 파일을 좀 더 변형? 확장?시키는 내용~~저번의 Point클래스를 템플릿화 하였었는데, 이 클래스 템플릿을 기반으로 Point같이 또 템플릿 클래스의 객체를 저장하려면 어떻게 해야할까? 답은!!그냥 평소 하던대로 하면 됨.단지 괄호가 늘 뿐임.BoundCheckArray> oarr(50);  //이런식으로!BoundCheckArray*> oparr(50);  //포인터는 이런식으로! 참고로 포인터는 아래처럼도 됨typedef Point* POINT_PTR;   BoundCheckArray oarr(50); /* Point.h */#ifndef __POINT_H_#define __POINT_H_#include using na..
2023.01.20전 티스토리에 썼던 거 옮기기#윤성우의 열혈 c++ 프로그래밍 ch 13-2 (p.540~553)01. 기본 예제 #include using namespace std;template class Point{private: T xpos, ypos;public: Point(T x=0, T y=0):xpos(x), ypos(y){} //생성자 이니셜라이저로 초기화 void ShowPos() const ///상태 출력 함수(변경x) { cout pos1(3, 4); //템플릿 클래스 pos1.ShowPos(); Point pos2(2.4, 3.6); //템플릿 클래스 pos2.ShowPos(); Point pos3('p', 'f'); //템플릿 클래스 pos3.ShowPos(); return..
rim08
'✨언어/c++' 카테고리의 글 목록