This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why can't you add a new class in Segger ?

What hidden settings am I missing this time in the awful Segger studio ?

I get an error :

unknown type name class

When I compile with this new class called Test.cpp :

.cpp file:

#include "Test.h"


Test::Test()
{
    
} 

and the .h file :

#include <stdlib.h>
#include <stdio.h>

    class Test
    {
        
        
    public:
        
        Test();
     
    
        
    private:
        
         
    
    };

EDIT:

Not sure why people are down voting but I think it's a real problem, at least for a beginner .

if I change the main to main.cpp I get 250 errors, some of them are :

'->' cannot appear in a constant-expression
'&' cannot appear in a constant-expression
a cast to a type other than an integral or enumeration type cannot appear in a constant-expression

They are coming from C files used by Nordic (drivers and libraries). The project was an example project from SDK, and I'v added other things to it.

I asked some people about it on the net, and they said I can't just mixed C and C++ files, so for example:

//main.cpp
#include "flash.h"
int main(void){}

Will produce errors because I include C file in C++ file , where the C might not be properly writen for C++.

Some of the errors comes from lines like this :

NRF_GPIOTE_TASKS_OUT_0     = offsetof(NRF_GPIOTE_Type, TASKS_OUT[0]), /**< Out task 0.*/
Parents
  • Thanks a lot, I have actually seen this page and tried it all, nothing helps. My question is, if you want to write a complex embedded application, you probably would like to use C++ to make it more powerful( arn't you? ) and you will always have C code from the drivers, and the libraries. So at some point you would like to include a c++ file to your code. To do that I did as you suggested, changed main to be cpp , so I can include cpp. Then everyone says you can't do that. So what CAN I do to use C++ ? :)

Reply
  • Thanks a lot, I have actually seen this page and tried it all, nothing helps. My question is, if you want to write a complex embedded application, you probably would like to use C++ to make it more powerful( arn't you? ) and you will always have C code from the drivers, and the libraries. So at some point you would like to include a c++ file to your code. To do that I did as you suggested, changed main to be cpp , so I can include cpp. Then everyone says you can't do that. So what CAN I do to use C++ ? :)

Children
No Data
Related