Hi Scott,

This is regular use of polymorphism through virtual member functions : you 
**dynamically** allocate whatever subclass of std::ostream (e.g., 
std::ofstream) and you store the returned pointer value into a pointer to base 
class (std::ostream*). When deleting this pointer, independently from the type 
of the variable you call delete on, the virtual destructor mechanism will 
ensure the destructor of the subclass you allocated is called.

Thus, you could call delete on _stream and have your stream properly closed.

Having said that, I would strongly advise against manual use of new and delete, 
especially when you are not the owner of the pointer you are playing with. Just 
call flush on the stream. This eventually synchronizes the most derived class 
through pubsync (https://en.cppreference.com/w/cpp/io/basic_ostream/flush).

Best,
Gabriel
_______________________________________________
gem5-users mailing list -- gem5-users@gem5.org
To unsubscribe send an email to gem5-users-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to