Pages: [1]   Go Down
Author Topic: Making a library: I must be missing some steps...  (Read 365 times)
0 Members and 1 Guest are viewing this topic.
BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I looked at the example at http://www.arduino.cc/playground/Code/Library and there is some mention there about compiling the .h and .cpp file and an object file that must be deleted if the source is changed. Now, compile with what? I guess the IDE does not generate object files...

I coded a simple .h and .cpp file in notepad then tried to import it into the sketch I have in Arduino IDE 022. Is this not possible?

I get these errors when I try to run the below sketch:

testclass:-1: error: new types may not be defined in a return type
testclass.cpp:3: note: (perhaps a semicolon is missing after the definition of 'testclass')
testclass:-1: error: two or more data types in declaration of 'setup'
testclass.cpp: In function 'void setup()':
testclass:4: error: request for member 'addnum' in 'tc', which is of non-class type 'testclass ()()'


testclass.h:
Code:
#ifndef testclass_h
#define testclass_h

#include <WProgram.h>

class testclass{
   public:
      testclass();
      int addnum(int a, int b);
}
#endif

testclass.cpp:
Code:
#include <testclass.h>

testclass::testclass(){}

int testclass::addnum(int a, int b)
{
   return (a+b);
}

Sketch:
Quote
#include <testclass.h>
testclass tc();

void setup(){
  tc.addnum(1,1);
}

void loop(){
  
}


Somebody please enlighten me!

Old guy.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18815
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
testclass tc();

Do you mean:

Code:
testclass tc;
Logged


0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 323
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

... and don't ignore this error:


testclass:-1: error: new types may not be defined in a return type
testclass.cpp:3: note: (perhaps a semicolon is missing after the definition of 'testclass')


You're missing a semi-colon:

testclass.h:
Code:
#ifndef testclass_h
#define testclass_h

#include <WProgram.h>

class testclass{
   public:
      testclass();
      int addnum(int a, int b);
}; // semi-colon required
#endif


!c
Logged

BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys! Another set of eyes is always a good thing! I will eventually get up to speed...

Old guy.
Logged

Pages: [1]   Go Up
Jump to: