본문 바로가기

반응형

System Programmings

(80)
[C++] typedef로 멤버 함수 포인터 사용 #include using namespace std; // typedef int (*TYPE)(int); 일반 함수를 typedef로 만든는 형식 class ask { public: int x; int f(int k); ask(); }; int ask::f(int k) { x=k; cout
[C++] typedef로 함수 포인터 사용 #include using namespace std; typedef int (*TYPE)(int); int f(int); int main() { f(3); TYPE x; x=&f; x(5); return 0; } int f(int k) { k*=k; cout
[C++] 클래스에서 static과 소멸자 역할 확인 #include using namespace std; class ask { public: static int cnt; // 객체 생성시 객체 생성수 카운트 static void print(); int obj; ask(); ask(const ask& pt); ~ask(); // 소멸자 }; int ask::cnt=0; // static 변수 초기화 void ask::print() { cout
[C++] 동적 할당 및 소멸자 사용 (얕은 복사의 문제점) #include using namespace std; class dynamic { public: int *arr; dynamic(int size); // 생성자 ~dynamic(); // 소멸자 }; dynamic::dynamic(int size) { arr=new int [size]; //메모리 동적 할당 } dynamic::~dynamic() { delete[] arr; // arr 동적 할당 메모리 해제 arr=NULL; // 에러 방지 위해 NULL 삽입 } int main() { int usize; cin >> usize; dynamic arr1(usize); for(int i=0; i
[C] 파일 입출력 끝부분 인지 확인 if(feof(File open val)!=0) break; printf("data : %c", ch);
[C] 1, 2차 배열의 포인터 형식 #include int main() { int m[5]={1,2,3,4,5}; int *b=m; int a[2][3]={1,4,3,4,5,6}; int (*k)[3]=a; printf("%d", *(b+1)); //형식 기억하기 printf("%d", *(a[1]+1));/형식 기억하기 return 0; }
[C++] C++ 문자열 스타일 #include #include #include using namespace std; int main() { string s="the flower of eden"; string d; d=s; cout
[C++] 클래스 기본 구성 및 접근자 #include using namespace std; ////////////////클래스 정의/////////////////// class oop { public: // 멤버 함수 oop(); oop(int x, int y); oop(const oop& pt); //복사 생성자 void print(); private: // 멤버 변수 int _x; int _y; public: // 접근자 void Setx(int inix); void Sety(int iniy); int Getx(); int Gety(); }; ///////////////함수 기능//////////////////// oop::oop(const oop& pt) { _x=pt._x; _y=pt._y; } void oop::Setx(int in..

반응형