I would like to know what is lacking in my code. The Aduino compiler, IDE version 1.8.0, generates error "'swSerial' was not declared in this scope". The code is the three attached short files that are contained in a folder called "object_scope".
Thanks for any help.
PS. Obviously, if the fifth line of the attached file "mylib.cpp" is commented out as it is, the error will not be generated. In this case the code is compiled OK.
mylib.h (70 Bytes)
mylib.cpp (162 Bytes)
object_scope.ino (240 Bytes)
in your cpp...
#include "mylib.h"
#include <SoftwareSerial.h>
extern SoftwareSerial swSerial;
void printSum(int a, int b) {
int sum = a+b;
swSerial.println (sum); // generates error "'swSerial' was not declared in this scope"
}
Thanks for the quick reply. I will try it tomorrow morning..
In the Useful Links post at the top of this Forum is a section called C++ Programming. There is a subsection on Scope that you might find useful.
Problem solved.
Many thanks to BulldogLowell that cared do give me a short and precise answer.
Thanks to econjack for showing the link about scope.