Pages: [1]   Go Down
Author Topic: Trying to write a library  (Read 367 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.cpp (7.6 KB - downloaded 16 times.)
* SNAD01.h (1.45 KB - downloaded 11 times.)
« Last Edit: January 24, 2013, 05:29:05 pm by Retroplayer » Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 69
Posts: 2166
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

SNAD01_SendChan != SNAD01_sendChan
Logged


Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wow.... I must have looked at that 100 times. smiley-sad

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

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 69
Posts: 2166
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 69
Posts: 2166
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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()'
Logged


Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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().
Logged

Pages: [1]   Go Up
Jump to: