したがって、次のように使用できるインデント出力クラスを作成したいと思います。
Debug f;
f.open("test.txt");
f << Debug::IndS << "Start" << std::endl;
f << Debug::Ind << "test" << std::endl;
f << Debug::IndE << "End" << std::endl;
出力は次のとおりです。
Start
test
End
したがって、IndS は現在のインデントを出力してインデントを増やし、Ind は現在のインデントを出力し、IndE はインデントを減らして現在のインデントを出力します。私はそれを次のように作成しようとしました:
class Debug : public std::ofstream {
public:
Debug();
~Debug();
private:
std::string IndentText;
int _Indent;
public:
void SetIndentText(const char* Text);
inline void Indent(int Amount);
inline void SetIndent(int Amount);
inline std::ofstream& Ind (std::ofstream& ofs);
inline std::ofstream& IndS(std::ofstream& ofs);
inline std::ofstream& IndE(std::ofstream& ofs);
};
Debug::Debug () : std::ofstream() {
IndentText = " ";
}
Debug::~Debug () {
}
void Debug::SetIndentText (const char* Text) {
IndentText = Text;
}
void Debug::Indent (int Amount) {
_Indent += Amount;
}
void Debug::SetIndent(int Amount) {
_Indent = Amount;
}
std::ofstream& Debug::Ind (std::ofstream& ofs) {
for (int i = 0;i < _Indent;i++) {
ofs << IndentText;
}
return ofs;
}
std::ofstream& Debug::IndS (std::ofstream& ofs) {
ofs << Ind;
_Indent++;
return ofs;
}
std::ofstream& Debug::IndE (std::ofstream& ofs) {
_Indent--;
ofs << Ind;
return ofs;
}
したがって、これにはいくつかの問題があると思います。
コンパイルされません。
no match for 'operator<<' (operand types are 'std::ofstream {aka std::basic_ofstream<char>}' and '<unresolved overloaded function type>') ofs << Ind; candidates are:
何とかエラーすべてのコンストラクターをオーバーライドするわけではありません。これを行う方法はありますか?
IndentText = " ";
すべてのコンストラクターを書き直して、オーバーロードされたコンストラクターをデリゲートする必要があると思います
誰かがこれで私を助けてくれますか? ありがとう!