Class composition, passing by reference - what I do wrong?

I'm writing a class "Clock" (see attachments) which implements a general clock functionality. I want this class to be reusable in different projects, so it has to have some access to a variables of the main program.

Class TimestampProvider is a way to use a global timestamp variable as oppose to call "millis()" inside the class "Clock". It is an abstract class and it has to be subclassed in a particular program.

#ifndef TIMESTAMPPROVIDER_H_
#define TIMESTAMPPROVIDER_H_


class TimestampProvider {
public:
	virtual unsigned long getTimestamp() const = 0;
	virtual ~TimestampProvider(){};
};


#endif /* TIMESTAMPPROVIDER_H_ */

In the main program I make a subclass of TimestampProvider which is supposed to have an access to a global variables:

class MillisProvider : public TimestampProvider {


public:


	unsigned long int getTimestamp() const;


};





unsigned long int MillisProvider::getTimestamp() const {


	Serial.println("inside getTimestamp()");


	return 0;


}

Then I'm creating the objects:

MillisProvider msp;


Clock  clock(msp);

The problem is when in the loop I call a method of the class "Clock" which contains a call "timestamp.getTimestamp()" (for example "clock.increaseHours()") my Arduino resets.

Clock.cpp (928 Bytes)

Clock.h (537 Bytes)

I got it. The reference member timestamp must be initialized in the constructor initializer block, not in the body of the constructor.