0

I am currently receiving the following message:

Error receive from Arduino IDE: request for member 'EEPROMWriteAny' in 'eType', which is of non-class type 'EEPROMAnyType()'

I do not think I am passing the variables by reference properly in my code, as that is what seems to be the main problem that causes the error written above. Or is having EEPROMWriteAny and EEPROM ReadAny in a class of a class what is causing this error? Do I have to point from the EEPROMAnyType class and then point to the U class? Is EEPROMReadAny even in a nested class?

I have supplied the header file, cpp source file, arduino example code using the EEPROM library and how I defined the keywords of the classes below. I have also supplied a picture of how my library looks like in its folder in case there is something wrong with that as well.

Header file:

#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 file:

#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 code:

#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);
}

Here is how I defined the keywords for the class EPPROMAnyType:

EEPROMAnyType   KEYWORD1
EEPROMReadAny   KEYWORD2
EEPROMWriteAny  KEYWORD2

enter image description here

Darren
  • 68,902
  • 24
  • 138
  • 144
John B.
  • 15
  • 6
  • 1
    `EEPROMAnyType eType();` should be `EEPROMAnyType eType;` if you want to have an instance. Otherwise you're just declaring a function named `eType`. – πάντα ῥεῖ Apr 23 '16 at 08:04

1 Answers1

0

EEPROMAnyType eType(); - compiler would interpret this statement as function declaration with the name as eType and it's return type as EEPROMAnyType. eType hence would not be an instance of EEPROMAnyType and any use of eType in sense of an instance of a class would produce the error. Hope this helps.

vamsee
  • 36
  • 3
  • Great! Thank you! I have found a number of other issues with the code.But I am working through them now. If I get stuck again I will be sure to post again. – John B. Apr 29 '16 at 05:28