I am trying to use typeid() but i keep getting an error im not sure why.
void RandomAttributes(Shape * S)
{
// pointer need for down casting
MyTriangle * triPtr;
MyRect * rectPtr;
MyCircle * circPtr;
//downcast base class pointer to derived class pointer
if (typeid(*S).name == "MyTriangle")
{
triPtr = dynamic_cast<MyTriangle *>(S);
// reset the rectangle object to some known, legal values
triPtr->SetPosition(p);
triPtr->SetLength(S->GetWindowHeight() / 10);
}
else if (typeid(S).name == "MyRect")
{
rectPtr = dynamic_cast<MyRect *>(S);
// reset the rectangle object to some known, legal values
S->SetPosition(p);
rectPtr->SetLength(S->GetWindowHeight() / 10);
rectPtr->SetWidth(S->GetWindowWidth() / 10);
}
else
{
circPtr = dynamic_cast<MyCircle *>(S);
circPtr->SetPosition(p);
circPtr->SetRadius(S->GetWindowHeight() / 10);
}
}
a shape (base class) pointer is being passed into this function which could be pointing to a Mytriangle, Mycircle, or MyRect Object. I believe dereferenceing the pointer should be working but I guess not.
ex. typeid(*S).name
I already tried S, *S, and &S. So whats left??