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();
}
串口输出:
基于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();
}
串口输出: