C++的类现在大家都有一个初步的了解了,那么现在我们来看看深入的研究一下类的方法。我们从一个电子表格入手:
—————————————
#pragma once
#include <iostream>#include <string>using namespace std;
——————————————–
今天我给出一个单元格的设计方案,现在大家思考一个问题,要怎么才能够通过我们今天的单元格为基础来设计一个电子表格。
今天的内容不多,作为一个深入class的引爆器,如果一旦展开,就不好收拾,所以我们还是如同前面一样,分步细说,恰逢周五,特留这个问题给大家周末思考。
—————————————
#pragma once
#include <iostream>#include <string>using namespace std;
namespace My_Code{
class SpreadSheetCell
{
public:
SpreadSheetCell();
SpreadSheetCell(string str);
SpreadSheetCell(double initvalue);
SpreadSheetCell(const SpreadSheetCell&
);
~SpreadSheetCell();
SpreadSheetCell&
operator=(const SpreadSheetCell&
);
void SetDoubleValue(const double doublevalue);
void SetStringValue(const string stringvlaue);
double GetDoubleValue();
string&
GetStringValue();
SpreadSheetCell&
operator+(const SpreadSheetCell&
cell);
protected:
double stringtodouble(const string str);
string doubletostring(double value);
double m_value;
string m_Str;
};
}
——————————————–
今天我给出一个单元格的设计方案,现在大家思考一个问题,要怎么才能够通过我们今天的单元格为基础来设计一个电子表格。
今天的内容不多,作为一个深入class的引爆器,如果一旦展开,就不好收拾,所以我们还是如同前面一样,分步细说,恰逢周五,特留这个问题给大家周末思考。