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
}
#endif2.LINKFLAGS加-lsupc++(不然包含析构函数会报错)
3.Demo效果