목록프로그래밍언어 (95)
nakka soft world !
소멸자는 여러개 만들 수 없고, 1개만 만들 수 있음. 파라메터 없음.소멸자를 만들지 않으면 컴파일러가 만듦. class Point{private:int x;int y;public:Point() { cout
default function, delete function - C++11/14 class Point{private:int x;int y;public:Point() {}Point() = default; // default를 하지 않아도 되나 관례상 하는 경우 있음. Point(int a, int b) { cout
class Point{private:int x;int y;public:Point() {cout
class Stack{private :int ids;int* buff; public:Stack() { idx = 0; } // OK // friendfirend void foo(); // 멤버함수는 아니지만 친구니까 Private변수 접근이 가능하다. 꼭 필요할때만 사용하도록. 연산자 재정의 때 주로 사용.friend class AAA; // AAA안에 있는 모든 멤버 함수는 Provate접근가능하다. }; void foo(){Stack s;s.idx = 0; // friend 이면 ok }
1. 전역변수와 일반함수 #incude using namespace std; int buff[10] = { 0 };int idx = 0; void push(int a) ( buff[idx++] = a; }int pop() {return buff[--idx]; } int main(){push(10);push(20); cout idx)]; } int main(){Stack s1, s2;s1.idx = 0; s2.idx = 0;push(&s1, 10);push(&s1, 20);cout
void Add(int ar, int ai int br, int bi, int* sr, int* si){*sr = ar + br;*si = ai + bi; } int main(){int ar = 1, ai = 1; // 1+1i;int br = 2, bi = 2; // 2+2i;int sr = 0, si = 0; Add(ar, ai, br, bi, &sr, &si); } C언어에는 복소수가 없음.. 구조체를 만든 뒤 Add함수 구현 struct Complex{int re;int im; } Complex Add(const Complex& c1, const Complex& c2){Complex temp = { c1.re + c2.re, c1.im + c1.re }return temp; } int main()..
C++ Explicit Casting int main(){int n = 10; // 4바이트 메모리 double* p1 = &n; // errordouble* p1 = (double*)&n; // ok *p1 = 3.4; // OK이더라도 운이 좋으면 Crash. 운나쁘면 메모리 침범} int main(){const int c = 10; // 상수 int* p2 = &c; // errorint* p2 = (int*)&c; // ok *p2 = 20; cout
reference 1. 기초int main(){int n = 10; // 메모리 4바이트 메모리 할당int* p = &n; int& r = n; // 기존 메모리(변수)의 별칭을 부여 하는 것 cout
namespace 1. 선언namespace Audio{void init(){cout