#include "timevalue.h"
#include <sstream>
#include <iomanip>
#include <cstdio>
//
// Time values in the spreadsheet.
//
usingnamespace std;
constchar* TimeValue::theValueKindName = "Time";
constchar* TimeValue::valueKind() const
// Indicates what kind of value this is. For any two values, v1 and v2,
// v1.valueKind() == v2.valueKind() if and only if they are of the
// same kind (e.g., two numeric values). The actual character string
// pointed to by valueKind() may be anything, but should be set to
// something descriptive as an aid in identification and debugging.
{
return theValueKindName;
}
Value* TimeValue::clone() const
{
returnnew TimeValue();
}
TimeValue* TimeValue::scale(scalar) const
{
returnnew TimeValue(d,h,m,s);
}
#ifndef TIMEVALUE_H
#define TIMEVALUE_H
#include "value.h"
//
// Numeric values in the spreadsheet.
//
class TimeValue: public Value
{
int d;
int h;
int m;
int s;
staticconstchar* theValueKindName;
public:
TimeValue():d(0),h(0),m(0),s(0) {}
TimeValue (int day, int hour, int min, int sec): d(day),h(hour),m(min),s(sec) {}
staticconstchar* valueKindName() {return theValueKindName;}
virtualconstchar* valueKind() const;
virtual Value* clone() const;
TimeValue* scale(double scalar) const;
};
#endif
Here is value.h which I believe that line 28 is really trying to reach?
#ifndef VALUE_H
#define VALUE_H
#include <string>
//
// Represents a value that might be obtained for some spreadsheet cell
// when its formula was evaluated.
//
// Values may come in many forms. At the very least, we can expect that
// our spreadsheet will support numeric and string values, and will
// probably need an "error" or "invalid" value type as well. Later we may
// want to add addiitonal value kinds, such as currency or dates.
//
class Value
{
public:
virtual ~Value() {}
virtualconstchar* valueKind() const = 0;
// Indicates what kind of value this is. For any two values, v1 and v2,
// v1.valueKind() == v2.valueKind() if and only if they are of the
// same kind (e.g., two numeric values). The actual character string
// pointed to by valueKind() may be anything, but should be set to
// something descriptive as an aid in identification and debugging.
virtual std::string render (unsigned maxWidth) const = 0;
// Produce a string denoting this value such that the
// string's length() <= maxWidth (assuming maxWidth > 0)
// If maxWidth==0, then the output string may be arbitrarily long.
// This function is intended to supply the text for display in the
// cells of a spreadsheet.
virtual Value* clone() const = 0;
// make a copy of this value. Typically implementd by a subclass S
// as: return new S(*this);
protected:
virtualbool isEqual (const Value& v) const = 0;
//pre: valueKind() == v.valueKind()
// Returns true iff this value is equal to v, using a comparison
// appropriate to the kind of value.
friendbooloperator== (const Value&, const Value&);
};
inlinebooloperator== (const Value& left, const Value& right)
{
return (left.valueKind() == right.valueKind())
&& left.isEqual(right);
}
#endif
Because scale returnes a pointer to a TimeValue, shouldn't it be :
(I use brackets to make sure I get the precedence right).
That is use the -> pointer for access rather than a . (dot)?