発行します上記のエラーを引き起こす主な問題であると思われるように、私は自分のコードで参照によって変数を正しく渡しているとは思わない。 EEPROMWriteAnyとEEPROM ReadAnyがクラスのクラスでこのエラーの原因となっていますか? EEPROMAnyTypeクラスをポイントしてからUクラスをポイントする必要がありますか?ネストされたクラスでもEEPROMReadAnyですか?非クラス型エラーは、ポインタは、私は現在、以下のようなメッセージを受信してい
私は、EEPROMライブラリを使用してヘッダファイル、cppソースファイル、arduinoサンプルコード、および以下のクラスのキーワードをどのように定義したかを指定しました。 また、私の図書館がそのフォルダ内でどのように見えるかの写真を提供しました。
ヘッダファイル:
#ifndef EEPROMAnyType_h
#define EEPROMAnyType_h
#include <Arduino.h>
#include <EEPROM.h>
class EEPROMAnyType
{
public:
template <class U> int EEPROMReadAny(unsigned int addr, U& x); //Reads any type of variable EEPROM
template <class U> int EEPROMWriteAny(unsigned int addr, U& x);//Writes any type of variable to EEPROM
private:
int i;
const byte *p[];
byte *p[];
};
#endif
CPPファイル:
#include "Arduino.h"
#include "EEPROM.h"
#include "EEPROMAnyType.h"
template <class U> int EEPROMAnyType::EEPROMReadAny(unsigned int addr, U x)
{
int i;
byte* p[sizeof(x)] = (byte*)(void*) x; //(void*) makes variable x "typeless" and then (byte*) casts the typeless variable as a byte type
for(i = 0; i < sizeof(x); i++){ // Why can I not declare i as an integer in the for loop?
p[i]= EEPROM.read(addr+i);
}
return i;
}
template <class U> int EEPROMAnyType::EEPROMWriteAny(unsigned int addr, U x)
{
int i = 0;
const byte* p[i] = (const byte*)(const void*) x;
for(i = 0; i < sizeof(x); i++){
EEPROM.write(addr+i, p[i]);
}
return i;
}
Arduinoのコード:ここで
#include <Arduino.h>
#include <EEPROM.h>
#include <EEPROMAnyType.h>
EEPROMAnyType eType(); // used to call EEPROMAnyType which can write/read any kind of data type to/from EERPOM
int addr = 10; //memory location to be pass by value to EEPROMAnyType functions
String *p;// To pass by reference to EEPROMAnyType functions
String x; //will be assigned to EEPROM location
void setup() {
x = "memory";
p = &x;
Serial.begin(9600);
Serial.println("Hello World"); //shows start point of code
eType.EEPROMWriteAny(addr, *p); //Writes to EEPROM memory 10
x = eType.EEPROMReadAny(addr, *p); //assigns bytes from EEPROM memory location to x
}
void loop() {
Serial.print("x: ");
Serial.println(x);
Serial.print("no. of bytes stored in x: ");
Serial.println(EEPROMWriteAny(addr, p));
delay(1000);
}
は、私はクラスEPPROMAnyTypeのキーワードを定義した方法です:
EEPROMAnyType KEYWORD1
EEPROMReadAny KEYWORD2
EEPROMWriteAny KEYWORD2
インスタンスを作成する場合は、 'EEPROMAnyType eType();'は 'EEPROMAnyType eType;'にする必要があります。さもなければ、 'eType'という名前の関数を宣言しています。 –