1.把main.c後綴名改為main.cpp
/*****************************************************************************
*
* File Name : main.c
*
* Description: main
*
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
* All rights reserved.
*
* Author : dave
*
* Date : 2014-6-14
*****************************************************************************/
#include "wm_include.h"
class Line
{
public:
void setLength( double len );
double getLength( void );
Line(); // 這是構造函數聲明
~Line(); // 這是析構函數聲明
private:
double length;
};
// 成員函數定義,包括構造函數
Line::Line(void)
{
printf("Object is being created\n");
}
Line::~Line(void)
{
printf("Object is being deleted\n");
}
void Line::setLength( double len )
{
length = len;
}
double Line::getLength( void )
{
return length;
}
#ifdef __cplusplus
extern "C" {
#endif
void UserMain(void)
{
printf("\n user task \n");
Line line;
// 設置長度
line.setLength(6.0);
printf("Length of line : %lf\n", line.getLength());
#if DEMO_CONSOLE
CreateDemoTask();
#endif
//用戶自己的task
}
#ifdef __cplusplus
}
#endif
2.LINKFLAGS加-lsupc++(不然包含析構函數會報錯)
3.Demo效果