I am doing an IOT project, so I am using multiple different libraries for my different hardware. I want to make my main look clean and simple so I want to put all the functions for the sensor into one library and call it with one function in the begin and loop. However, I have encountered an error, which is "expected unqualified-id before '.' token" at several lines of the code. I have added comments where it says the error is. And also, it says that I do not I have a class type for mq2 in line 8 of the cpp file
"'((firealarm*)this)->firealarm::mq2' does not have class type mq2.begin();"
cheers mate, that solve the "expected unqualified-id" error. However, the does not have classes error is still there whenever I called it in my cpp file.
I have updated the code. Right now the current problem is it saying I do not have the class type whenever I try calling a function from a different library. the error says
"firealarm.cpp:10:3: error: '((firealarm*)this)->firealarm::mq2' does not have class type"
That’s not how you instantiate a member variable that’s an instance of a class and whose constructor takes a value. I corrected that for you. See below. Also, see what I meant when I requested you to put everything in one file? That way people don’t have to create 3 separate files in order to compile your code. You stand the best chance of getting help if you make it easy for people to help you. You can separate them later.
Also, your ‘begin()’ method claims to take an integer parameter, but then you try to call it from ‘setup()’ without a argument. You need to fix that before it will compile. By the way, why is it an integer? Do you ever expect the baud to be negative? What happens if you want a baud rate greater than 32767?
Oh I get it now. About the all the code in one file, I thought you meant to put it all in one text file and insert in the comments. My mistake, sorry about that.
about the int baudrate, I was looking at a tutorial on youtube and he call it that way just to proof he can call and set the variable in the h file.