sirleech/Webduino

Code doesn't go in .h files

Closed this issue · 3 comments

The whole library is a single .h file.

That is not the right way to write a library.

The class definition etc goes in the .h file, the code (WebServer::whatever(...)) goes in a .cpp file.

This is done so that you are able to include the .h file in multiple code files and not have it throw up hundreds of errors about multiple definitions.

As it stands now, you cannot use this library in multiple tabs in your sketch.

The reason for doing this is to make the server more configurable. The top of the Webduino.h file has several config variables that change the behavior of the server depending on #defines. If the code was in a .cpp file, it couldn't be affected by those defines in the user program as it would be built separately.

If you've got multiple files in your sketches, it's trivial to separate the code or to just use the web server object from one file.

NOTE: there is a way to pull the .h file in without defining methods... see the lines

/* define this macro if you want to include the header in a sketch source
file but not define any of the implementation. This is useful if
multiple source files are using the Webduino class. */
#ifndef WEBDUINO_NO_IMPLEMENTATION

so if you say

#define WEBDUINO_NO_IMPLEMENTATION
#include "Webduino.h"

in your other source files, you should be good.