用C++实现的SDK跨平台心得体会

C/C++的跨平台特性相比于Java更加原生(Java是一次编译到处运行,而C/C ++则需要拿着源码重新编译一遍),实现一个C/C++跨平台程序一般有几点做法:
1.使用Qt
2.使用ANSI C/C++支持的函数
3.条件编译,如
#if defined(__symbian32__)
  #define xx_platform  xx_platform_symbian
#elif defined(__win32__)||(_win32)
  #define xx_platform  xx_platform_win32
#elif defined(__apple__cc)
  #if environment_iphone_os_version_min_required__>=40000
    #define xx_platform  xx_platform_apple_ios
  #else
    #define xx_platform  xx_platform_apple
4.对库中所用数据类型进行跨平台定义,如把int封装为xx_int,把string封装为xx_string,把bool封装为xx_bool...
5.对域定义符进行跨平台定义,如private封装为xx_private,把public封装为xx_public...
6.完全自定义消息或事件,杜绝使用特定系统的消息和响应函数(这就是为什么Qt要创造signal和slot的原因)
posted @ 2015-01-28 18:40  一名老程序员  阅读(862)  评论(0编辑  收藏  举报