Transferring program into library with classes...no work

Hello,

very much stuck with this so please some advise.

Situation:

I made a program which prints on a 20-4 display big characters (4-4).

The program is working fine but, as I want to use this functionality into an other program I want to transfer it into a library.

The good:
My first attempt with a very simple header and no classes did work perfect.
The header looked like this:

#ifndef BigPatch_h
#define BigPatch_h

#include <Arduino.h>

void BigFontInit();
void PrintBigPatch (int patchnummer, byte patchletter);
void LoadChars();
void PrintBigNumber (byte number, byte col);

#endif

With this header and .cpp file all is fine.
To me this means that the program and lib_functionality is working fine, no errors in that.

The Bad:
And now I'd like some help as I can not figure this out.

I want to make a better library with classes so I changed the header to:

#ifndef BigPatch_h
#define BigPatch_h

#include <Arduino.h>

class BigPatch
{
public:
BigPatch(); //constructor
void Init();
void PrintBigPatch (int patchnummer, byte patchletter);

private:
void LoadChars();
void PrintBigChar (byte number, byte col);
};

#endif

(*note that some name_changes occured but that is all fine)

I just pick out 1 function I made in the .cpp : the init()

void BigPatch::Init() {
lcd.init();
lcd.backlight();
lcd.clear();
//BigPatch.LoadChars(); uncomment this just as a first test
}

And, finally the main .ino program (just a part of it):

#include "BigPatch.h"
BigPatch Big(); // make constructor Big

and in the setup I put
Big.Init();

And here is where it all goes wrong:

the compiler says
request for member 'Init' in 'Big', which is of non-class type 'BigPatch()'

And that is what I do not understand as my Init function is available in the header and available in the .cpp program but it still says it's not a class of BigPatch.

Anyone a light to shine on this?

Thanks!

Hello

There are two problems

  • Your constructor is not defined
    So change BigPatch(); //constructor to BigPatch() {}; //constructor
    Or define it in the .cpp
    Or simply remove this line to use the default constructor

  • When the constructor doesn't have parameters, you initialize objects of this class without using parenthesis
    So change BigPatch Big(); to BigPatch Big;
    ( else, this would be considered by the compiler as the prototype of a function named Big, which takes no parameter and returns an object of type BigPatch.. )

Where is 'lcd' declared and how does "BigPatch.cpp" see the declaration?

Thank you GUIX!

I did what you suggested and the compiler is getting through!

I googled a lot on this question but could not find an answer and now it's compiling and with some more changes now it's working!

Strange thing is that when I looked up a tutorial for making a lib they do not use the {} in the header as I didn't do at first (I used https://www.teachmemicro.com/create-arduino-library/ for learning).

About the Big();...edit: understand it (but could never come up with it so will make a note to myself for the future, thanks for explanation)

Thanks again for your help!

Thanks John,

I left that part out of the posting here as the program is really big but therefore I said that all program is working fine with the no_class definition.

But all is solved now, made the changes guix wrote and not only the compiler got through that small part of the code, now that I fully gave the code to the compiler all is working like it should!

Yes but they define the constructor later in the .cpp