Original Post
I'm having a strange problem where typeid() lies to me. It insists that a pointer I'm giving it is a pointer to a base class when it's actually a pointer to a derived class. Yes, I'm dereferencing the pointer. I'm using almost identical code (it has the same form, but it involves different classes) elsewhere in my program and it works fine. Here's the applicable code: a CSharedFileInfo instance is created and passed to a function that takes a CSharedFSObject pointer:
CSharedFileInfo* newFile = new CSharedFileInfo(&FileData);
AddFSObject(newFile);
this is the function with a couple comments to explain the issue:
void CSharedFileDir::AddFSObject(CSharedFSObject* FSObj)
{
// note: inserts at the top of the list, because it's faster
Node* NewNode = new Node;
NewNode->FSObj = FSObj;
// the list is empty, just point the head at the new node
if(!Head)
{
Head = NewNode;
}
else
{
// replace and point to the old head
Node* NextPtr = Head;
Head = NewNode;
NewNode->Next = NextPtr;
}
// !!!!!! - THIS IF STATEMENT FAILS:
// if it's a file, not a dir, increment the file counter
if(typeid(*FSObj) == typeid(CSharedFileInfo))
NumFiles++;
// THIS MESSAGE BOX SAYS "class CSharedFSObject":
AfxMessageBox(typeid(*FSObj).name(), MB_OK, NULL);
return;
}
and if you need proof that CSharedFileInfo is a child of CSharedFSObject: class CSharedFileInfo : public CSharedFSObject Any help will be appreciated! This one has been driving me nuts for hours.