This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using C++ and C in CCS v5.x

Hi Everyone,

I have been given the task of doing some development using C++  in  an existing project done in  Code Composer Studio 5.x on Windows 7, service pack 1

The  project currently has only has 'C' code.

I am totally new to using C++ in this scenario. 

I have written the following small project comprising of just three small files just to get the hang of it

The TI compiler gives error in main.c file saying that it does not recognize Battery identifier

I will greatly appreciate if someone could help me correct my three files so that it does the job properly.

Once I know the right way,, I can start developing the actual programs

Many thanks in advance

Best regards,

Hamid Sultan

/************************ Start of Battery.hpp    *****************************************/

#ifndef BATTERY_HPP_
#define BATTERY_HPP_

/*  Battery.hpp   */
#ifdef __cplusplus


class Battery {
public:

Battery();
virtual ~Battery();

};

#endif // __cplusplus


#endif /* BATTERY_HPP_ */

/************************ Endt of Battery.hpp    *****************************************/

/**************************  start of Battery..cpp  ************************************************************* */

#include "Battery.hpp"

#ifdef __cplusplus
extern "C" {
Battery::Battery() {
// TODO Auto-generated constructor stub

}

Battery::~Battery() {
// TODO Auto-generated destructor stub
}
}
#endif

/********************       end of Battery.cpp   ***************************************************/

/**********************  Start of main.c  ****************************************************/

#include "Battery.hpp"


int main(void) {

Battery * bat = new Battery(); 
bat->~Battery();

return 0;
};

/************************  End of main.cpp  *****************************************************/

  • Hamid Sultan said:
    The TI compiler gives error in main.c file saying that it does not recognize Battery identifier

    The compiler probably thinks this is C code, and not C++ code.  Rename the source file to main.cpp, or use the option --cpp_default.

    Thanks and regards,

    -George