I am just learning and have started with simple examples, well mostly. The problem had me hunting in my first attempt at a library for literally hours without any progress.
I had taken a working sketch and transplanted it into a library using the Morse example as a template and it just wouldn’t compile …
I eventually replicated the error in the simple Morse class :-
test1:7: error: request for member ‘dot’ in ‘morse’, which is of non-class type ‘Morse ()()’ <<
This is repeated for all functions when they are referenced even though the compiler is happy with the include and init.
This is a snipet of my sketch followed by the top of the .h and .cpp files.
With the commented ‘A’ lines are in play all is well, while ‘B’'s give me the error :-
class Morse
{
public:
// Morse(int pin); // A
//Morse(); // B
And the Morse.cpp
// Morse::Morse(int pin) // A
// Morse::Morse() // B
{
// _pin = pin; // A
// _pin = 13; // B
pinMode(pin, OUTPUT);
}
I have played around with all sorts of configurations and even naming conventions, in the process generating all sorts of errors due to omission, mismatch and even poor construct. All could be traced to mistakes and generally were identified within verbose compilation comments.
However no matter what I do I cant get a library, any library, to work if the construct is devoid of arguments and I cant find a reason.
The error is always the same … request for member X in Y, which is of non-class type Y ()().
I assume this means that Y is not being recognised as a class when its constructor is Y() as opposed to Y(a)
Of course I could simply accept it and always put in a dummy argument, just to satisfy the construct constraint, but then I wouldn’t be learning.
I would very much appreciate any insight … Even if it just to point out how silly I am being.
Thanks
Al
The pin variable isn't declared (as it was the argument), so either replace it with _pin, or simply with 13 (you don't need that additional, useless variable).
Edit: actually, the rest of the code may need that variable _pin, so don't remove it.
I appreciate the input but that isn't it ....
pin is only used when it is declared as part of the Morse(int pin) construct.
_pin is declared as 'private int' in the Morse.h file
The problem is more subtle than that ... any constructor I try like this :-
ConName::ConName(int iDummy) { }
ConName::SomemFunc(with or without args){}
will work just fine, assuming it matches in the header source and sketch.
However this :-
ConName::ConName() { }
ConName::SomemFunc(with or without args){}
bombs out every time, with the same error, as soon as a function is referenced.
I have to be missing something stupid but it isn't bad variable scope or naming ...
The error imply s that ConName isn't a class and cant therefore have a member function, the one that was just called!
Not sure what you mean by (9,12,1) perhaps its a diferent example, here is the tiny one I am playing with.
all I need to do to se the error is arrange the constructor not to have an argument, nothing else matters.
well apart from all three file matching of course.
the actual functionality of the sketch is immaterial, even with all the functions empty so they do nothing the error still occurs if you reference one.
You STARS .... Thanks a bunch. Just tried it and it works like a charm.
I am somewhat embarrassed by the fact that I just spent 12 hours or so mucking with this.
It wasn't all because I left a couple of brackets in where there should have been any that accounted for way more than I like to admit to.
I suppose had I not been brand new to all of it I may have spotted the silliness .... Ah well.
Whilst we are on the subject of classes how do I go about creating a class global static .... I think that right.
I want a variable defined in the class / library that is accessible to all instances.
The requirement is so count the instances as they are created ....
That code is not correct. You don't have an instance called foo. You have a class called foo, with instances called fooa and foob. While you can access static data of the class using the scope resolution operator (Serial.print(foo::ivalue);), you need an instance name to call methods.
Either
Serial.print(fooa.GetValue());
or
Serial.print(foob.GetValue());
will print 10.
But, defining a class like that sucks. Really. Use some white space so it is readable.