In c++ how do I successfully chain classes together in the following example?
<p>In c++ how do I successfully chain classes together in the following example?</p>

<pre><code>Clock timer;

std::cout &lt;&lt; timer.getElapsedTime().inSeconds();
std::cout &lt;&lt; timer.getElapsedTime().inMilliseconds();
</code></pre>

<p>How do I write the code successfully?</p>

<pre><code>class ElapsedTime
{
private:
    double _start;

public :
    ElapsedTime(double start)
    {
        _start = start;
    }
    double inSeconds() const
    {
        return (std::clock() - _start ) / (double) CLOCKS_PER_SEC;
    }

    double inMilliseconds() const
    {
        return ((std::clock() - _start ) / (double) CLOCKS_PER_SEC) * 1000;
    }
};


class Clock
{
private:
    std::clock_t _start;
    double _duration;

public:

    Clock()
    {
        _start = std::clock();
    }

    ElapsedTime getElapsedTime() const {
        return ElapsedTime(_start);
    }

    double reset()
    {
        _duration = (std::clock() - _start ) / (double) CLOCKS_PER_SEC;
        _start = std::clock();
        return _duration;
    }

};
</code></pre>

<p>edit: made the suggested changes by pm100</p>

<p>Although the class chain still returns a value like .7e-05</p>

<p>and if I try to use const in the following manner I get a segmentation fault</p>

<pre><code>ElapsedTime const&amp; getElapsedTime() const {
        return ElapsedTime(_start);
</code></pre>