【K70EK_T7_MQX例程】004编译执行C++程序

By Mcuzone

调试串口波特率:115200-uart2
基于MDKK70-EK_T7硬件平台

串口输出:
global: Constructed OK
local: Constructed OK
heap: Constructed OK
heap: deallocation
local: deallocation

说明:编写了一个HelloWorld的类,在cplus_task中打印各对象的状态
class HelloWorld {
private:
   int check_init;
   const char *id;
public:
   HelloWorld() {
      check_init = 0x1234567;
   }
   ~HelloWorld() {
      _io_printf("%s: deallocation\n",id);
   }
   void print(const char *x) {
      id = x;
      if (check_init == 0x1234567) {
         _io_printf("%s: Constructed OK\n",id);
      } else {
         _io_printf("%s: Constructor not called\n",id);
      }
   }
};

HelloWorld global;

/*TASK*-----------------------------------------------------

* Task Name    : cplus_task
* Comments     :
*    This task prints the state of each object
*
*END*-----------------------------------------------------*/

void cplus_task
   (
      uint_32 initial_data
   )
{
   { // Scope for local to destruct
      HelloWorld local;
      HelloWorld *heap;

      global.print("global");
      local.print("local");
      heap = new HelloWorld;
      if (heap != 0) {
         heap->print("heap");
         delete heap;
      } else {
         _io_printf("heap: new failed\n");
      } /* Endif */
   } // local should destruct
   _io_fflush(stdout);
   _task_block();
}

串口输出: 

例程及示例:

链接: http://pan.baidu.com/s/1qWk6D4o 密码: ap7v
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值