C++

W800/W801 SDK C++compile Demo

Publish in 2022-09-01 09: 50: 44

1. the main. c postfix 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 () ;    // This is the constructor declaration
      ~Line () ;   // This is the destructor declaration
 
   private: 
      double length; 
}; 
 
// Member function definition,  Inclusive constructor
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; 
    // Set length
    line. setLength (6. 0) ;  
    printf ("Length of line :  %lf\n",  line. getLength () ) ; 

#if DEMO_CONSOLE
    CreateDemoTask () ; 
#endif
//user-owned task
}

#ifdef __cplusplus
}
#endif

2. LINKFLAGS add-lsupc++ (Otherwise, the inclusion destructor will report an error)
image. png
3. Demo effect
image. png

0 Pieces of review

publish
problem