How to create a library for a function and a struct?


i found examples of putting class library, have 2 functions , 2 structs , putting them in class wouldn't make sense. nevertheless move them file can include in different projects. 

how that? 

code: [select]
struct examplestruct1{
  float foo;
  int bar;
};

struct examplestruct2{
  float abc;
  char test;
};

examplestruct1 examplefunction1(int foo) {
    // ...
}

examplestruct2 examplefunction2(examplestruct1 bla) {
    // ...
}


should paste .h or .hpp file , done it?

in folder sketches stored there should folder called libraries. if not, make it.
inside folder, make folder library. call folder utilslib, can call whatever want.

inside folder, put following .h , .cpp files:
.h header
code: [select]
struct examplestruct1{
  float foo;
  int bar;
};

struct examplestruct2{
  float abc;
  char test;
};

examplestruct1 examplefunction1(int foo);
examplestruct2 examplefunction2(examplestruct1 bla);

.cpp code
code: [select]

#include "___.h" // above file

examplestruct1 examplefunction1(int foo) {
    // ...
}

examplestruct2 examplefunction2(examplestruct1 bla) {
    // ...
}

in c++ important separate declaration of function it's definition. that's why need split functions .h , .cpp file.


Arduino Forum > Using Arduino > Programming Questions > How to create a library for a function and a struct?


arduino

Comments

Popular posts from this blog

Help with Missing Filename Error?

more info - Joomla! Forum - community, help and support

Using phone battery to power a plane.