본문 바로가기
728x90
CPP 순수 가상 함수(Pure Virtual Function), 추상 클래스(Abstact Class), 인터페이스(Interface) 순수 가상 함수(Pure Virtual Function)란? 순수 가상 함수는 구현이 없는 virtural 함수! virtual void function() = 0; vitural void function() = {} cpp의 가상 함수는 반드시 재정의할 필요 없다. 가상 함수가 뭔지 모른다면 아래 링크 클릭! 더보기 https://developer-eun-diary.tistory.com/52 CPP 가상 함수(Virtual Function) 가상 함수(virtual function)란? 부모 클래스(기본 클래스)에서 선언되어 자식 클래스(파생 클래스)에 의해 재정의되는 멤버 함수 가상 함수는 기본 클래스 내에 virtual 키워드로 함수를 선언 가상 함 developer-eun-diary.tistory.. 2022. 1. 18.
CPP 가상 함수(Virtual Function) 가상 함수(virtual function)란? 부모 클래스(기본 클래스)에서 선언되어 자식 클래스(파생 클래스)에 의해 재정의되는 멤버 함수 가상 함수는 기본 클래스 내에 virtual 키워드로 함수를 선언 가상 함수를 왜 사용할까? 가상 함수를 사용하지 않으면 오버라이딩 시에 문제가 있을 수 있음! 자식 클래스에서 포인터 변수로 객체에 접근할 때 의도치 않게 동작할 수 있다. cpp에서는 컴파일러는 포인터 변수가 가리키고 있는 변수의 타입을 기준으로 함수를 호출하지 않는다. 포인터 타입을 기준으로 함수를 호출! 아래 코드를 보자. class A { public: void check() { std::cout 2022. 1. 18.
CPP friend 클래스와 함수 friend 클래스란? 다른 클래스의 private 및 protected 멤버에 접근할 수 있게 해주는 키워드! friend class A; 클래스 내에서 friend로 다른 클래스를 등록해놓으면, private와 proteced로 접근하지 못하게 만든 변수 또는 함수에 접근 가능! 아래 예제 코드를 보자 class A { private: int num; friend class B; }; class B { void set_A_num(A &a, int n) { a.num = n; } }; 클래스 B의 set_A_num함수에서 A의 클래스의 num에 직접 접근해서 값을 변경했다. 원래 A 클래스의 num은 private이라 다른 클래스에서 직접 접근하지 못한다. 그러나 A클래스에서 friend 키워드를 통해.. 2022. 1. 18.
CPP template template이란? 함수나 클래스를 다시 작성하지 않고도 여러 자료형으로 사용할 수 있도록 하게 만들어 놓은 틀 template는 cpp 기본 내장이어서 헤더를 딱히 써주지 않아도 된다. 그렇다면 template를 왜 쓸까? 밑에 코드를 보면 쉽게 이해 가능! int i_sum(int a, int b) { return a + b; } double d_sum(double a, double b) { return a + b; } 원래는 sum을 구현하기 위해, 매개변수의 자료형이 다를 때마다 함수를 새로 만들어줘야 했다. 이게 너무 번거로우니깐 자료형을 지정하지 않고 모든 자료형을 매개변수로 사용 가능한 함수를 만들기 위해 template 사용! typename으로 이름을 지정하고, 지정한 이름을 자료형처럼.. 2022. 1. 17.
CPP Container와 Iterator Container cpp에서 처음 접한 개념 container가 뭘까? container는 말 그대로 저장소로라고 생각하면 쉽다. 같은 타입의 여러 객체를 저장하는 일종의 집합이다. 컨테이너는 클래스 템플릿이다. 컨테이너 변수를 선언할 때 컨테이너에 포함할 요소의 타입을 명시할 수 있다. 그렇다면 왜 배열을 안 쓰고 container를 쓸까? container 종류 중 하나인 "vector"를 예로 들어 생각해보자. int a[10]과 같이 선언해서 int 배열을 쓸 수 있는데, 굳이 왜 vector를 쓸까? int a[10]; vector b(10); vector에는 배열에 특화된 여러 유용한 함수들을 가지고 있다. 예로 뒤에 값을 추가할 수 있는 push_back이 있다. 많은 값을 저장하는 것에 특.. 2022. 1. 17.
CPP struct class 기본 액세스 한정자 CPP에서는 C와 다르게 struct에서 함수, 생성자, 소멸자를 다 가지고 있을 수 있다! 짱 신기!!!🥳 그렇다면 class와 struct의 다른 점은 뭘까? 둘은 다 똑같은데 액세스 한정자(Access Modifiers)가 다르다 class = private struct = public class와 struct는 서로 또는 각자를 상속할 수 있다 default inheritance access specifier를 알아보자! 자식 부모 엑세스 한정자 struct struct public struct class public class struct private class class private 자식의 액세스 한정자를 따라간다고 생각하면 간단하다 struct A { }; class B { }; stru.. 2022. 1. 17.
VSCode cpp 버전 설정하기 VSCode 설치 후 cpp를 쓰는데 아래 그림과 같이 백터 초기화가 안됨...!!!!! 아마 예상으로는 cpp 버전이 98로 되어있는거 같다..🥺 code -> 기본 설정(References) -> 설정(Settings)으로 들어간다 확장 -> c/c+로 들어간다 또는 cpp standard를 검색한다 cpp standard를 원하는 버전으로 바꿔주면 설정 끝! 2022. 1. 17.
Git commit 시간 변경하기 마지막 Commit 날짜를 현재 날짜로 설정 git commit --amend --no-edit --date "$(date)" 마지막 Commit 날짜를 임의의 날짜로 설정 "" 사이에 원하는 연도, 날짜, 시간을 입력! git commit --amend --no-edit --date "Sun 16 Jan 2021 12:00:00 KST" 2022. 1. 17.
leetcode 8) String to Integer (atoi) LV. Medium 🧐 https://leetcode.com/problems/string-to-integer-atoi/description/ String to Integer (atoi) - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function.. 2022. 1. 14.
leetcode 452) Minimum Number of Arrows to Burst Balloons LV. Medium 🧐 https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/ Minimum Number of Arrows to Burst Balloons - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons.. 2022. 1. 14.
728x90