본문 바로가기

4.개발 및 운영 환경

C++멤버함수 포인터 크기 확인

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

 

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

 

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

직접 확인하기 바란다.

#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;
}

 

 

 

반응형