Please help.
I want to create a library ClassCommon, which will be a constant visible in this library as well as other me of a library and the main program.
Advise me how to create this library, for example, constants "Position" and you show me how this constant appeal of this and other library?
Thank you
My solution:
/********************************************************
ClassCommon.cpp
*********************************************************/
#include "Arduino.h"
#include "ClassCommon.h"
ClassCommon::ClassCommon()
{
const byte position = 9;
}
/********************************************************
Example
*********************************************************/
void example()
{
byte abc = positon; // ERROR ! ! ! !
}
/********************************************************
ClassCommon.cpp
*********************************************************/
#ifndef ClassCommon_h
#define ClassCommon_h
#include "Arduino.h"
class ClassCommon
{
public:
ClassCommon();
byte position;
private: ;
};
#endif
/********************************************************
MAIN
*********************************************************/
#include <ClassCommon.h>
ClassCommon Common;
byte position = Common.position; // OK. No error
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
ClassCommon::ClassCommon()
{
const byte position = 9;
}
Create a new variable, named position, and assign it a value of 9. That variable immediately goes out of scope, so you wasted your time.
/********************************************************
Example
*********************************************************/
void example()
{
byte abc = positon; // ERROR ! ! ! !
}
What is the ERROR ! ! ! ! ? ? ? ? ? ? ? ? ?
I need variable Position is visible in all libraries and the main program.
I need variable Position is visible in all libraries and the main program.
What is the problem?
In the void Example I not see constant Positoin
/********************************************************
Example
*********************************************************/
void example()
{
byte abc = positon; // ERROR ! ! ! !
}
C:\Program Files (x86)\Arduino\libraries\ClassCommon\ClassCommon.cpp:49:14: error: 'positon' was not declared in this scope
byte abc = positon; // ERROR ! ! ! !
^
Chyba kompilace.
C:\Program Files (x86)\Arduino\libraries\ClassCommon\ClassCommon.cpp:49:14: error: 'positon' was not declared in this scope
byte abc = positon; // ERROR ! ! ! !
^
Chyba kompilace.
Your class contains:
byte position;
strcmp("positon", "position") != 0
I do not understand.
The name position is NOT the same as the name positon
It was a typo.
void example()
{
byte abc = position; // ERROR ! ! ! !
}
C:\Program Files (x86)\Arduino\libraries\ClassCommon\ClassCommon.cpp:49:14: error: 'position' was not declared in this scope
byte abc = position; // ERROR ! ! ! !
^
Chyba kompilace.
How to solve it?
In other Class Position I see only in their own class ClassCommon not.
In other Class Position
Position is NOT a Class.
Post ALL of your code, AS YOU HAVE TYPED IT - Not from what you think it might have looked like once upon a time. Post your error messages, too.
#include "Arduino.h"
#include "ClassCommon.h"
ClassCommon::ClassCommon()
{
position = 9;
}
/********************************************************
Example
*********************************************************/
void example()
{
byte abc = position; // ERROR ! ! ! !
}
C:\Program Files (x86)\Arduino\libraries\ClassCommon\ClassCommon.cpp:49:14: error: 'position' was not declared in this scope
byte abc = position; // ERROR ! ! ! !
^
Chyba kompilace.
/********************************************************
Example
*********************************************************/
void example()
{
byte abc = position; // ERROR ! ! ! !
}
The function example() is not a class method. Why do you assume that it can access class data?
How it should be properly recorded?
How it should be properly recorded?
Is example() supposed to be a class method? If so, you forgot to put it in the header file, and you failed to define it properly.
If not, your expectation that a random function will be able to access class fields is completely unrealistic.
Yes, the example () procedure is used in the file ClassCommon. How therefore it should look correct writing of this procedure?
How therefore it should look correct writing of this procedure?
Like any other class method:
void ClassCommon::example()
{
}