Trying to instantiate a DS3231 real time clock within a library I'm trying to write a library encapsulating things that I do with a DS3231 real time clock. I have managed to compile a sketch using the library, but it apparently blows up when attempting to call clock methods such as getTime().

Header:

// JBP_DS3231.h
#ifndef __JBP_DS3231_h__
#define __JBP_DS3231_h__

#include &lt;SD.h&gt;
#include "DS3231.h"
#include "Arduino.h"

class JBP_DS3231
{
  public:
    JBP_DS3231();
    String TimeStamp();
  private:
    DS3231* _realTimeClock;
};

#endif


cpp:

#include &lt;JBP_DS3231.h&gt;
#include &lt;SD.h&gt;
#include "DS3231.h"
#include "Arduino.h"

JBP_DS3231::JBP_DS3231() {
  String thisTime = "";

  _realTimeClock = &amp;DS3231(SDA, SCL); 

  Serial.println("About to try to get time from RTC."); // Last line we hear from.

  thisTime = _realTimeClock-&gt;getTimeStr();
  Serial.print("Time in constructor is: ");
  Serial.println(thisTime);
}

String JBP_DS3231::TimeStamp() {
  String timeStamp = "";

  Serial.println("In TimeStamp().");
  timeStamp = _realTimeClock-&gt;getDateStr(FORMAT_LONG, FORMAT_MIDDLEENDIAN, '/');
  Serial.print("Value of timestamp is: ");
  Serial.println(timeStamp);
  timeStamp.concat(" ");
  timeStamp.concat(_realTimeClock-&gt;getTimeStr());
  Serial.println(timeStamp);

  return timeStamp;
} 


Script:

const String WHO_AM_I = "JBP_DS3231_library_test.ino";
const    int VERSION = 0;

#include &lt;JBP_DS3231.h&gt;

void setup() {
  Serial.begin(9600);
  AnnounceAwakening();

  JBP_DS3231 johnsRTC;
  Serial.println(johnsRTC.TimeStamp());
}

void loop() {
  return;
}

void AnnounceAwakening() {
  Serial.print("Sketch ");
  Serial.print(WHO_AM_I);
  Serial.print(" version ");
  Serial.print(VERSION);
  Serial.println(".");
  Serial.println("");
}
You appear to be providing a pointer to a constructor, not to an object.  Either create a new object with new, or instantiate the object separately and provide the pointer to the object:

_realTimeClock = new DS3231(SDA, SCL); 


Better still, extend the existing class and implement your own methods:

clsss JBP_DS3231 : public DS3231 {
    public:
        JBP_DS3231(uint8_t d, uint8_t c) : DS3231(d, c) {
            String thisTime = "";
            Serial.println("About to try to get time from RTC."); // Last line we hear from.

            thisTime = getTimeStr();
            Serial.print("Time in constructor is: ");
            Serial.println(thisTime);
        }

        String TimeStamp() {
            String timeStamp = "";

            Serial.println("In TimeStamp().");
            timeStamp = getDateStr(FORMAT_LONG, FORMAT_MIDDLEENDIAN, '/');
            Serial.print("Value of timestamp is: ");
            Serial.println(timeStamp);
            timeStamp.concat(" ");
            timeStamp.concat(getTimeStr());
            Serial.println(timeStamp);

            return timeStamp;
        } 
};

void setup() {
    Serial.begin(115200);
    JBP_DS3231 myRTC(SDA, SCL);
    Serial.println(johnsRTC.TimeStamp());
}

void loop() {
}


(Note: untested)