class Product
{
...
}
class Perishable : public : Product
{
public:
int getday();
}
int main()
{
Product *temp;
//due to some coding
//temp could point to either Perishable object or Product object that is determine //during runtime
cout<< ((Perishable*)temp)->getday() ;// is there other way to achieve this typecasting seems dangerous
temp는 Product 객체에 temp를 지정하면 temp-> getday()가 유효하지 않으며이 문제를 방지하는 방법을 알지 못합니다. 어떤 상황으로 인해서, 나는 부양 할 수있는 제품에서만 getday()를 사용할 수 있지만, temp가 부패하기 쉬운 객체 또는 Product 객체를 가리키는 지 어떻게 확인할 수 있습니까?C++ 기본 다형성
어떤 도움을 주시면 감사하겠습니다/
}
이것은 다형성의 목적을 무력화시키는 것 같습니다. 또는 귀하의 질문에 대한 오해입니다. – grep
"다운 캐스트"에 대해 질문하는 것 같습니다. http://en.wikipedia.org/wiki/Downcast? – reuben