Error creating simple library file: IDE thinks constructor is a function

I wrote and debugged a lot of code in a header file. I wanted to make it into a library so I followed the tutorial at: http://arduino.cc/en/Hacking/LibraryTutorial. I got a lot of errors so I decided to make an ultra simple library to familiarize myself with the problems. Unfortunately even the ultra simple code gave error messages like: error: no matching function for call to 'testRTC::testRTC()' where testRTC should have been my constructor, not a function call.
My sketch:

#include <Arduino.h>    // correct for 1.0.2	
#include <testRTC.h>
#include <Wire.h>

testRTC rtc;

void setup() { Serial.begin(9600); delay(2000); }
void loop() { delay(2000); Serial.println("LOOP: "); }

my header file:

// test real time clock library
#ifndef testRTC_h
#define testRTC_h

#include <Arduino.h>
#include <Wire.h>

#define RTC_ADDRESS 0x68
#define ENABLE_SQ_WAVE_REG  0x07
#define ENABLE_SQ_WAVE      0x10   // default for 1 HZ output
// alternatives are: 0x10=1 HZ, 0x11=4 KHZ, 0x12=8 KHZ, 0x13=32 KHZ
//  ***************************************
class testRTC     // Real Time Clock 
  {
  public:
  testRTC(byte freqSQwave);                       // constructor
  void setClock(byte *clockSetting);              // set clock with array 
  void getClock(byte *clockSetting);              // put clock in array
  void enableSQwave(boolean enable, byte freq);   // enable/disable SQ wave
  protected:
  byte decToBcd(byte val);
  byte bcdToDec(byte val);
  };
#endif

The beginning of my .cpp file located in my library directory:

// Local real time clock
#ifndef testRTC_h
#define testRTC_h
#endif

#include <Arduino.h>
#include <Wire.h>
//#include "testRTC.h"   // for real time clock

//  ***************************************
testRTC::testRTC(byte freqSQwave = 0) {;}     // constructor
//  ***************************************
void testRTC::setClock(byte *clockSetting)    // points to setting
  {
  byte value;
  Wire.beginTransmission(RTC_ADDRESS);
  Wire.write( (byte) 0);                      // register pointer value
  for (int i = 0; i < 7; i++)                 // write the setting
    {
    value = clockSetting[6 - i];              // start with seconds value
    if (value == 255) break;
    Wire.write(decToBcd(value));              // convert as writing to RTC
    }
  Wire.write( (byte) 0);                      // may be to reset register pointer 
  Wire.endTransmission();
  }
//  ***************************************

The full error message was:
aaa:5: error: no matching function for call to 'testRTC::testRTC()'
C:\Arduino-IDE\libraries\testRTC/testRTC.h:16:
note: candidates are: testRTC::testRTC(byte)
C:\Arduino-IDE\libraries\testRTC/testRTC.h:14:
note: testRTC::testRTC(const testRTC&)

In the sketch (aaa.ino) if I comment out "testRTC rtc;" it will compile but then there is no instance of the class I want to use. Seems as soon as the class is instantiated it tries to call a constructor and does not find the one I provided.

Any help would be greatly appreciated.

turbosnail:
I wrote and debugged a lot of code in a header file. I wanted to make it into a library so I followed the tutorial at: http://arduino.cc/en/Hacking/LibraryTutorial. I got a lot of errors so I decided to make an ultra simple library to familiarize myself with the problems. Unfortunately even the ultra simple code gave error messages like: error: no matching function for call to 'testRTC::testRTC()'

Well yeah, there's no testRTC::testRTC(), there's only testRTC::testRTC(byte freqSQwave)

I am not sure what you mean when you say "there's no testRTC::testRTC(), there's only testRTC::testRTC(byte freqSQwave)". That is what the IDE says but I do not have a function call to testRTC(). That is what the IDE is looking for, and it is NOT in my code. The error message states "no matching function for call to 'testRTC::testRTC()'" but I do NOT have a function call, only a constructor. The error message calls it a function but a constructor is not a function so I do not know what the error message indicates the IDE wants.
P.S.
The code I distilled the aaa.ino from worked fine as long as the constructor, methods and functions remained in the header file, it was only when I tried to separate out the class, constructor and methods into a .h and .cpp file that I ran into the errors.

testRTC rtc;

That calls the constructor, and you don't have such a constructor function.

class testRTC     // Real Time Clock 
  {
  public:
  testRTC(byte freqSQwave);                       // constructor

There is no mention there of a default argument.

Pardon my density, I have only been programming C++ for a few weeks, but when you say "There is no mention there of a default argument." Where do you mean, in the sketch or in the class definition? In the class definition I do have a parameter in the constructor and I tried putting one in the instantiation of the class with " testRTC rtc(0);" but I still get the errors. I tried "testRTC rte((byte) 0);" and still get errors. I added a constructor in the header file that does not require a parameter: " but still get errors. I took all code from the .cpp file and put it in the .h header file, commented out the code in the .cpp and compiled with NO errors. As far as I can tell what I have done is just like the tutorial but I get errors.

If someone could be more specific as to what is wrong it would help me a lot.

Yes I know the instantiation is calling a constructor but the IDE does not seem to recognize any of the code in my .cpp file which is in my library file with the header file.

turbosnail:
Pardon my density, I have only been programming C++ for a few weeks, but when you say "There is no mention there of a default argument." Where do you mean, in the sketch or in the class definition? In the class definition I do have a parameter in the constructor and I tried putting one in the instantiation of the class with " testRTC rtc(0);"

This seems like it should be correct. Now show the code and explain what errors you get.

Clearly I am doing something fundamentally wrong but I do not know what!!
I made the following changes:

class testRTC     // Real Time Clock 
  {
  public:
  testRTC(byte freqSQwave);                       // constructor
  testRTC();
  ...
  ...

In the .cpp file I added a constructor that needs no parameter:

//  ***************************************
testRTC::testRTC(byte freqSQwave = 0) {;}     // constructor with parameter
testRTC::testRTC() {;}                        // constructor with no parameter
//  ***************************************

in the sketch I made this change:

#include <Arduino.h>    // correct for 1.0.2	
#include <testRTC.h>
#include <Wire.h>

testRTC rtc(0);

void setup() { Serial.begin(9600); delay(2000); }
void loop() { delay(2000); Serial.println("LOOP: "); }

Now I get multiple errors beginning:

C:\Arduino-IDE\libraries\testRTC\testRTC.cpp:11:
error: 'testRTC' has not been declared
C:\Arduino-IDE\libraries\testRTC\testRTC.cpp:11: error:
ISO C++ forbids declaration of 'testRTC' with no type
C:\Arduino-IDE\libraries\testRTC\testRTC.cpp:12: error:
'testRTC' is not a class or namespace
C:\Arduino-IDE\libraries\testRTC\testRTC.cpp:12: error:
ISO C++ forbids declaration of 'testRTC' with no type
C:\Arduino-IDE\libraries\testRTC\testRTC.cpp:14: error:
'testRTC' is not a class or namespace
C:\Arduino-IDE\libraries\testRTC\testRTC.cpp:
In function 'void setClock(byte*)':
C:\Arduino-IDE\libraries\testRTC\testRTC.cpp:17:
error: 'RTC_ADDRESS' was not declared in this scope
etc. etc. etc.

I do not know why but the IDE does not seem to be recognizing the .cpp file and maybe not the .h file.
HELP!

OK, I was right; I was doing something fundamentally wrong. All I did to make it compile was change the .cpp file in the library directory. I commented out this:

/*
#ifndef testRTC_h
#define testRTC_h
#endif
*/

And it compiled. Tomorrow I will test the compile and research the correct way to use those preprocessor directives. Right now it is bedtime. I do not know how to mark the thread as solved; maybe tomorrow.

Thanks to all who tried to help. If any of you know of a link to info on the preprocessor stuff I would thank you imensely.

This doesn't achieve anything useful at the top of testRTC.cpp:

// Local real time clock
#ifndef testRTC_h
#define testRTC_h
#endif

Omit that.


The constructor needs to show it takes a default argument:

class testRTC     // Real Time Clock 
  {
  public:
  testRTC(byte freqSQwave = 0);                       // constructor

That's where the "= 0" goes. Not in the .cpp file.


However there's not much point because you don't use it (freqSQwave):

testRTC::testRTC(byte freqSQwave) {;}     // constructor

That #ifndef bit should only be in the .h file for a class, to prevent the declaration of the class being included twice. The first two lines go at the top and the last line ( #endif ) should be at the end of the file.

You don't put that into the .cpp file for the class.