Go Down

Topic: Trying to write a library (Read 557 times) previous topic - next topic


Jan 24, 2013, 11:26 pm Last Edit: Jan 24, 2013, 11:29 pm by Retroplayer Reason: 1
I am writing a library to interface with a Sonix SNAD01 Analog to Digital Converter. I used the softI2CMaster library as my basis for this and heavily modified it. But it won't compile, and the messages are making no sense to me.

First the compiler output:
Code: [Select]
SNAD01.cpp: In member function 'uint8_t SNAD01::SNAD01_Convert(uint8_t)':
SNAD01.cpp:113: error: 'SNAD01_sendChan' was not declared in this scope
SNAD01.cpp: At global scope:
SNAD01.cpp:269: error: no 'void SNAD01::SNAD01_sendChan(uint8_t)' member function declared in class 'SNAD01'
SNAD01.cpp:284: error: no 'void SNAD01::SNAD01_sendReg(uint8_t)' member function declared in class 'SNAD01'

I have attached the library and header to this post. It isn't complete yet, but I was trying to clean up any errors before I finished it up. These are the last ones I do not understand.

Maybe I am just going crosseyed here, but I just can't see the problem. Help?


SNAD01_SendChan != SNAD01_sendChan


wow.... I must have looked at that 100 times. :(

Now I feel stupid. Grr!! Stupid fonts. lol


It is a very common for this to happen, I know to look for it now. This is one of those errors that 100% of c/c++ programmers will encounter at least once.

Choosing cleaner names might help, I personnaly would remove the 'SNAD01_' prefix from the class members, the class encapsulates its features, so the function is already known to belong to a SNAD01.


Hmm.... great point! Every library I have looked at so far did it this way, so I assumed that it was to avoid some naming collision with other code. So, this will not happen?


You can't used reserved keywords like 'new' and 'float', but you can reuse any valid name as they are effectively in the scope of the class.

This is shown by the need to specify a class object to call an instance 'class_object.function()' or with static functions 'class_type::function()'


Thanks Pyro! I will clean it up in the final version.


Look at how many classed have begin() methods, and how many have print() and write() methods. Using a name as a class method that is the same as the name in another class is perfectly alright. In fact, its encouraged, if the method does the same thing, but for a different object.

LCDs can print(), Serial ports can print(), LED matrices can print().

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131