Java-like null for string and ofstream arguments in c++ -
i have java code (constructor)
recursivedescentparser ( std::string inputstream, bool fileservice, std::string filepathname, std::ofstream writer ) { input_ = inputstream; tokenizer_ = new tokenizer(inputstream); if (fileservice == true){ error = new errorhandling(fileservice, std::move(writer)); } else{ error = new errorhandling(fileservice, std::ofstream()); } compiled_ = ""; } tokenizer *tokenizer_; std::string input_, compiled_;
i emulate call within c++
recursivedescentparser *parser = new recursivedescentparser ( stream, false, null, null );
if use pointer arguments
std::string *str; std::ofstream *out
i can pass in nullptr if choose not use pointer arguments, can't pass null. can simulate passing null std::string , std::ofstream?
pointers 1 option say; create complications need either manage objects separately, or use smart pointers. shared pointers possibility, , give semantics quite similar java's object references (only reference counting rather garbage collection).
for nullable object type, use boost.optional, or implement own nullable wrapper class. there talk of optional
being included in future standard library; now, need boost that.
alternatively, might make more sense provide second constructor not take arguments @ all.
Comments
Post a Comment