Good Morning,
I am beginner in c++ and I need some help to implement a class to represent cell in excel.
The first problem I have is that I don't know how to define date
and the second is overloading some operators. Could you help me please ?
My code is :
Code:
#include<iostream>
#include<string>
using namespace std;
template<typename T>
class Cell {
public:
Cell(T d) : data(d) {}
T get_value() const;
void set_value(T x);
// overload operators
// bool operator == (const Cell&, const Cell&);
// bool operator > (const Cell&, const Cell&);
// bool operator = (const Cell&); // I don;t know which should be the parameter. "data" ?
private:
T data;
};
template<typename T>
T Cell<T>::get_value() const {
return data;
}
template<typename T>
void Cell<T>::set_value(T x) {
data = x;
}
// template<typename T>
// bool Cell<T>::operator == (const Cell& c1, const Cell& c2){
// bool ret = false;
// if ( c1.data==c2.data)
// ret = true;
// return ret;
// }
// template<typename T>
// bool Cell<T>::operator > (const Cell& c1, const Cell& c2){
// bool ret = false;
// if ( c1.data>c2.data)
// ret = true;
// return ret;
// }
int main() {
Cell<int> a1(12);
cout << a1.get_value() << endl;
Cell<float> b1(2.32);
cout << b1.get_value() << endl;
string s = "test";
Cell<string> c1(s);
cout << c1.get_value() << endl;
}
I would appreciate any help.
Thank you