What did i do wrong?

I want to create a "Base program" for my future projects, to handle all "default" tasks e.g WiFi, LED-/ Button handling and so on...

because of the size of my program i divide the Sketch in different classes and Files but now i have a problem i don't understand...

i wrote new Files with the same concept like my original Files but thoose are too big (>900 char)

this are my Files:

main.cpp

#include <Arduino.h>
#include "../lib/test.h"


/*
class Test {
  private:
        String name;

    public:
        Test(const char* &test)
        {
          this->name = test;
        }
        void showVal()
        {
          if(!Serial)
          {
            Serial.begin(115200);
          }
            Serial.println(name);
        }
};
*/

const char* val = "Hallo";
Test neu(val);
void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

test.cpp

#include "./test.h"

Test::Test(const char* &test)
{
    this->name = test;
}

void Test::showVal()
{
    if(!Serial)
    {
        Serial.begin(115200);
    }
    Serial.println(name);
}

and test.h

#include "Arduino.h"

class Test {
    private:
        String name;

    public:
        Test(const char* &test);
        void showVal();
};

In test.cpp and test.h is the same class like in main.cpp comment (line 5 - 24)

if i build all things (Test class, in main.cpp) in one file and remove the include "test.h" it works fine...
if i create my test class, in seperate file (test.h and test.cpp) but without parameter in constructor
i mean following:

test.cpp:
Test::Test(const char* &test) -> Test::Test()

test.h:
Test(const char* &test) -> Test::Test()

then it works fine too (i can compile it successfully...)

but if i want to use a parameter (with Reference value (call by Reference) or "normal" call by value) it dont works... in any case it ends up with the following Error:

ERROR with use of const char* &val) => call by reference

c:/users/username/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\nodemcu\src\main.cpp.o:(.text.startup._GLOBAL__sub_I_val+0x8): undefined reference to `Test::Test(char const*&)'
c:/users/justi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\nodemcu\src\main.cpp.o: in function `_GLOBAL__sub_I_val':
main.cpp:(.text.startup._GLOBAL__sub_I_val+0x17): undefined reference to `Test::Test(char const*&)'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\nodemcu\firmware.elf] Error 1



and without useage of references: (call by value)
c:/users/username/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\nodemcu\src\main.cpp.o:(.text.startup._GLOBAL__sub_I_val+0x8): undefined reference to `Test::Test(char const*)'
c:/users/justi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\nodemcu\src\main.cpp.o: in function `_GLOBAL__sub_I_val':
main.cpp:(.text.startup._GLOBAL__sub_I_val+0x1a): undefined reference to `Test::Test(char const*)'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\nodemcu\firmware.elf] Error 1

what is the Problem?? - the File itself? - can i pass parameters if i use classes in different Files?

=> in my original program its an Object but the error is the same...

i hope someone can help me...

Thanks for help ^^

j54j6:
I want to create a "Base program" for my future projects, to handle all "default" tasks e.g WiFi, LED-/ Button handling and so on...

Why do you have a main()? It's predefined by the API.

It would be much better to build separate files, one for each task, and include them as needed in the main program with the #include statement.

Regarding posting files, if the entire file is too big, please add it to your post as an attachment.

aarg:
Why do you have a main()? It's predefined by the API.

It would be much better to build separate files, one for each task, and include them as needed in the main program with the #include statement.

i dont have a function called "main()" i only use the File main.cpp because of the IDE i use...
I use platform IO, the default filename is main.cpp ^^

i already have one class/file per Tasktype e.g Filemanager class, LED class, Button class and so on...

But i don't understand why this program i post at the beginning... it has the same error...
i want to know why this program i postet above dont work... the problem is the same but much less problems for others to help me :slight_smile:

Thanks for your help ^^