티스토리 툴바


3.구현/개발2011/01/05 11:39

작성: http://ospace.tistory.com/,2011.01.04 (ospace114@empal.com)

 

다음은 간단한 소스 코드이다. C++에서 멤버 함수 포인터 크기는 4byte(x86인경우)가 아니다.

이를 눈으로 확인하기위한 예제이다. 놀라지 마시라~~~

직접 확인하기 바란다.

 

  1. #include <iostream>
    typedef void (*general_fun)();
    class base1 {}; class base2 {};
    // single inheritance class derived_s : base1 {}; // multiple inheritance class derived_m : base1, base2 {}; // virtual inheritance class derived_v : virtual base1 {}; // unknown class class unknown;
    typedef void (derived_s::*memFun_s)(); typedef void (derived_v::*memFun_v)(); typedef void (derived_m::*memFun_m)(); typedef void (unknown::*memFun_u)(); #define println(os) std::cout << os << std::endl
    int main(int argc, char* argv[]) {
    println("size of general funcion = " << sizeof(general_fun)); println("size of single instance member function = " << sizeof(memFun_s)); println("size of multiple instance member function = " << sizeof(memFun_m)); println("size of virtual instance member function = " << sizeof(memFun_v)); println("size of unknown instance member function = " << sizeof(memFun_u)); return 0; }

이 글은 스프링노트에서 작성되었습니다.

크리에이티브 커먼즈 라이선스
Creative Commons License

'3.구현 > 개발' 카테고리의 다른 글

Thunk와 용법1 - 다중 상속에서 가상함수  (0) 2011/01/12
코드 문서화  (0) 2011/01/07
C++멤버함수 포인터 크기 확인  (0) 2011/01/05
쓰레드별 전역변수 사용하기  (0) 2010/09/01
D-Bus란  (0) 2010/03/18
Syntaxhightlighter 2.x 사용하기  (0) 2009/11/13
Posted by ospace

댓글을 달아 주세요