c++(72)
-
[C++] 26. 상속
1. 상속의 개념_ 상속이란 무엇인가? #include #include using namespace std; // 상속의 개념 // 아래 구조체 monster와 player의 형태는 다르지만 공통된 속성과 기능이 있다 // 이는 중복되는 소스가 생기므로 효율이 떨어진다 // 중복되는 소스를 상위개념으로 해서 하나의 구조체(Charactor)를 만들어 놓고 // monster와 player에게 상속하게 만드는 것 // 하나의 부모 클래스로부터 특성이 조금씩 다른 자식 클래스를 얼마든지 파생시킬 수 있다. // 상속 관계의 아래쪽으로 내려올수록 더 많은 속성과 동작이 정의된다. // 위쪽의 선조 클래스는 멤버가 많지 않아 일반적이고 포괄적인 사물을 표현하는데 비해 // 아래로 내려올수록 후손 클래스의 멤버가..
2022.06.10 -
[C++] 25. 동적배열이란
#include using namespace std; void main() { int input; cout input; int* arr = new int[input]; for (int i = 0; i < input; i++) { arr[i] = i*2; cout
2022.06.07 -
[C++] 구조체 변수의 동적할당과 해제
#include using namespace std; struct Student { string name; int id; int age; Student() { cout
2022.06.07 -
[C++] 24. 동적할당이란
#include using namespace std; int dataNum = 150; // 동적할당 // new int; // delete 변수명; // 동적할당의 특징 : delete를 써서 직접 해제를 해줘야 한다 void main() { int num = 10;// 스택영역에 할당됨 int* numPtrA = #// 스택영역에 할당됨 cout
2022.06.07 -
[C++] 참조자를 사용해서 swap함수 만들기
#include using namespace std; // 참조자(call by reference) : 다이렉트로 주소접근 // 데이터타입& 변수명 void Swap(int& inputA, int& inputB) { int temp; temp = inputA; inputA = inputB; inputB = temp; } void main() { int a = 10; int b = 30; cout
2022.06.07 -
[C++] 23. 복사생성자 (참조자의 개념)
앞서 생성자와 소멸자를 공부하다가 생성자는 기본생성자가 있고 새로운 개념이 등장했다. 바로 '복사 생성자'라는 것인데, 복사 생성자(call by reference)란 자신과 같은 클래스 타입의 다른 객체에 대한 참조(reference)를 인수로 전달받아, 그 참조를 가지고 자신을 초기화하는 방법입니다. 복사 생성자는 새롭게 생성되는 객체가 원본 객체와 같으면서도, 완전한 독립성을 가지게 해줍니다. *참조자(call by reference)의 형태 : 데이터타입& 변수명 #include using namespace std; struct Monster { string name; float hp; float damage; // 기본 생성자 만들기 Monster() { cout
2022.06.07