ファイルから/へのオブジェクトの読み取りと書き込みの両方のクラスを作成したいと考えています。この目的を達成するために、テンプレート キーワードを使用します。
template<class T>
class A{
private:
std::string filePath;//This will use to indicate the path of proper file.
public:
void save(T a){
//write the given object to the file. The path is fetched by filePath
}
std::list<T> read(){
//read the file and put each line in the list. The path is fetched by filePath
}
A(std::string path):filePath(path){}
};
このメソッドを使用する場合、int、float などのプリミティブ型で使用した場合はすべて問題ありません。しかし、円、長方形などのオブジェクトを操作したいときに問題が発生します。問題を解決するにはどうすればよいですか