Using C++ with Visual Studio Code with Arduino for ESP8266

Hello,
I’m new in the usage of Visual Studio Code for NodeMCU/ESP8266. Everything worked quite well as Long as I use only c language and put all in one file (the main,cpp). But I would like to use C++ and also several source Code files. So practically I have two Problems somehow related.

When I place a simple Class that really doen’t do anything in the main file, it compiles. Creating an instance of this class works so far, as the Compiler doesn’t complain. But the linker creates Errors as it cannot reference all the class Methods (constructor and other functions).

I have a similar behavior when I put some c Code in a different file, located in the same Folder where my main file is located. The Compiler again doesn’t complain but when I try to use a function from the other file in my main file, I get again a linker error.

If I try to declare a class in a Header file, the Compiler complains About the word class. So it Looks to me as a c Compiler is used or the used one (I guess it’s xtensa-lx106-elf) works in c mode.

I’m using the Standard simple Settings and therefore my platformio,ini contains only
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
lib_extra_dirs = ~/lib
monitor_speed = 115200

May be I have to put this Topic into another Group, but I haven’t found something related. And it’s my first post in this comunity.
Searching now for my Hours already the Internet to any solution, I didn’t found something good. Any help or hint would be aprechiated.

Erwin

You need to provide a minimal example that shows what code / project you’re trying to compile exactly, then we can help.

I made a very simple example Project and surprisingly this works. I can make a C++ class in a different file and can use it in main.cpp. No Compiler error and no linker error.
On one Hand this is very nice but I have no idea why my first Project doesn’t work. It still doesn’t work but I see no real difference.
So for the Moment the Problem is solved. When it Comes back, I can put some Questions again.
Do I have to mark this Topic as solved or something closed? In other Forums I should do this, but here I haven’t read anything and haven’t seen (until now) such a button.

Erwin

Do you use CPP extension in both cases?