| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
- c++복습
- 씨쁠쁠내용정리
- 우분투
- turtlesim
- 터틀심
- ytmusicclone
- ytmusic
- 뇌인지과학
- 유튜브뮤직
- 인지신경
- c++로시작하는객체지향프로그래밍
- ROS2
- 인지신경과학
- 유튜브뮤직클론
- 터틀심별
- 뇌과학
- c++내용정리
- 뇌인지
- 실습문제
- numpy
- cpp로시작하는객체지향
- 우분투20.04
- 인지신경과학입문
- virtualbox
- 객체지향c++
- pandas
- 터틀심원
- 클론코딩
- 터틀봇
- cpp로시작하는객체지향프로그래밍
- Today
- Total
one님의 블로그
[C++로 시작하는 객체지향 프로그래밍] 내용 정리 3 본문
■ void f(int* p1, int* &p2) , f(q1, q2)
⇒ q1은 값에 의한 전달, *p1변경시, *q1변경, p1=q3로 바꾸면 q1변경X
⇒ q2은 참조에 의한 전달, *p2변경시, *q2변경, p2=q3로 바꾸면 q1변경O
- void m(int list[], int size) == void m(int* list, int size)
■ #include <algorithm>
- min_element(list, list+6) ⇒ 최소 요소에 대한 포인터 반환
- max_element, sort, random_suffle, find ⇒ 포인터 반환
■ 동적메모리 할당 ⇒ int* p = new int(4); ⇒ int는 동적 배열
- new 로 할당된 메모리 ⇒ delete/ 프로그램 종료 시까지 존재
- delete p; (or) delete [] llist; (배열일 때)
- new에 의해 할당된 메모리: freestore/heap 안에 존재
- (*p).length() == p->length()
■ this 포인터: 객체의 데이터 필드 참조 시, this->data= data 이런식
■ 소멸자(destructor): 객체 삭제시, 자동호출됨 (~Circle(), 틸드문자(~)가짐)
■ operator [] 함수: string 클래스의 멤버함수
- vector, operator+, operator< : string클래스의 비멤버함수
-예) s1.operator[] (0), operator+(s1, s2), operator <(s1, s2)
■ bool operator<(Rational &secondRational) const
- r1.operator<(r2) == r1<r2
■ 오버로딩에 의해 연산자 우선순위와 결합성 변경 불가
- 오버로딩에 의해 피연산자 개수 변경불가 (예) ++는 단항연산자
■ 오버로딩 불가능 연산자 : ‘ ?: ‘ , ‘ . ‘ , ‘ .* ‘ , ‘ :: ‘
■ 첨자 연산자 [] (subscript operator)
- (예) int& operator[](int index)
- [] 연산자는 접근자, 변경자로 동작
■ 증강대입연산자 (+=, -=, *=, /=, %=) ⇒ Lvalue 연산자임
- Rational& Rational::operator+=(const Rational &secondRational)
- r2 = r1 += Rational(2, 3)
■ 단항연산자 오버로딩 ⇒ Rational Rational::operator-()
- Rational r3=-r2
■ ++, --연산자 ⇒ Rational Rational::operator++() 전위 증가, Lvalue
- Rational Rational::operator++(int dummy) : 후위증가, Lvalue X
■ class Date{ … friend class a; …}; class a{… Date birthdate(2010,3,4);…}; 가능
string s2("Welcome");
s2.append(" to C and C++", 0, 5); //Welcome to C
s2.append(" to C and C++", 5); //Welcome to C
s2.assign("Dallas, Texas", 0, 5); //Dalla
s2.append(" to C and C++", 0, 5); //Dalla
string s1("Welcome");
string s2("Welcomg");
s1.compare(s2) //-2
s1.substr(3) //come
s1.substr(3,3) //com
s1.find("co") // 3
s1..find("co", 5) //-1 (없음) , string::npos 반환함
s2.insert(1, 4, 'B'); //WBBBBelcomg
stringstream ss;
ss << 3.1415;
string s = ss.str(); //itoa
- eof() : 문자열 스트림 내 모든 항목 읽었을 때, True 반환
※ 참조에 의한 전달이 더 효율적
getline(cin, city, '\n'); //엔터 기준으로 입력받음
Circle circleArray[3] = {Circle(3), Circle(4), Circle(5)}; //객체 배열
'학과 공부 > C++' 카테고리의 다른 글
| [C++로 시작하는 객체지향 프로그래밍] 10장 실습-2 (0) | 2024.10.27 |
|---|---|
| [C++로 시작하는 객체지향 프로그래밍] 10장 실습-1 (0) | 2024.10.27 |
| [C++로 시작하는 객체지향 프로그래밍] 10장 실습-3 (0) | 2024.10.27 |
| [C++로 시작하는 객체지향 프로그래밍] 내용 정리 2 (1) | 2024.10.27 |
| [C++로 시작하는 객체지향 프로그래밍] 내용 정리 1 (0) | 2024.10.27 |