KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have some C++ code (written by someone else) which appears to be calling the wrong function. Here's the situation: UTF8InputStreamFromBuffer* cstream = foo(); wstring fn = L"foo"; DocumentReader* reader; if (a_condition_true_for_some_files_false_for_others) { reader = (DocumentReader*) _new GoodDocumentReader(); } else { reader = (DocumentReader*) _new BadDocumentReader(); } // the crash happens inside the following call // when a BadDocumentReader is used doc = reader->readDocument(*cstream, fn); The files for which the condition is true are processed fine; the ones for which it is false crash. The class hierarchy for DocumentReader looks like this: class GenericDocumentReader { virtual Document* readDocument(InputStream &strm, const wchar_t * filename) = 0; } class DocumentReader : public GenericDocumentReader { virtual Document* readDocument(InputStream &strm, const wchar_t * filename) { // some stuff } }; class GoodDocumentReader : public DocumentReader { Document* readDocument(InputStream & strm, const wchar_t * filename); } class BadDocumentReader : public DocumentReader { virtual Document* readDocument(InputStream &stream, const wchar_t * filename); virtual Document* readDocument(const LocatedString *source, const wchar_t * filename); virtual Document* readDocument(const LocatedString *source, const wchar_t * filename, Symbol inputType); } The following are also relevant: class UTF8InputStreamFromBuffer : public wistringstream { // foo }; typedef std::basic_istream<wchar_t> InputStream; Running in a Visual C++ debugger, it shows that the readDocument call on a BadDocumentReader is calling not readDocument(InputStream&, const wchar_t*) but rather readDocument(const LocatedString* source, const wchar_t *, Symbol) </pr
Tags (comma-separated)
Save Edits
Cancel