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 ^^