Error message: undefined reference to `setup' and undefined reference to `loop '

Here is my code:

#ifndef __EMAIL__H_
#define __EMAIL__H_

class Email {
  String _from, _to, _subject, _body;

  public:

  Email(
    const String& from,
    const String& to,
    const String& subject,
    const String& body
  ) : _from(from), _to(to), _subject(subject), _body(body) {}

  const String& getFrom()    const { return _from; }
  const String& getTo()      const { return _to; }
  const String& getSubject() const { return _subject; }
  const String& getBody()    const { return _body; }
} ;

#endif

can you tell me what to do ?

PS.i am new, so pls dont use too many complicated words

That is only a snippet of code. Every sketch requires a function called 'setup' and a function called 'loop' and your code does not have either of those.

In the IDE, if you go to File -> New you will see the bare bones template of what a sketch needs to be. You can cut and paste your Email class into that.

yeah but into what, the void setup or void loop part

Have you tried this? ^^^^

many, many, many times

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Was asking OP

It sounds like you got this code from somewhere and don't know what do to do with it. If that is the case, you will need to learn some C/C++ programming if you want to use Arduino. Start small.

Normally, things like your code would go into an "Email.h" header file and would be accompanied by the Email.cpp file that implements all those functions in the class. Pretty advanced concepts for someone new..

Your "code" is an include file. As the others have noted, you need a sketch (a .ino) file with at least the setup() function and, within that .ino, #include "email.h" or whatever it's called.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.