johnnyICON
March 13th, 2005, 01:41 AM
Hi, I am trying to create a function that compare's two objects.
Here, take a look:
int Integer::compareTo(const NodeItem &anotherNodeItem)
{
int returnCode = 0;
Integer *otherInteger = dynamic_cast<Integer&>(anotherNodeItem);
if (otherInteger == NULL)
returnCode = ERROR_INCOMPATIBLE_TYPES;
else
returnCode = compareTo(*otherInteger);
delete otherInteger;
return returnCode;
}
The error I get when I try to compile is at this statement:
Integer *otherInteger = dynamic_cast<Integer&>(anotherNodeItem);
The error is this:
Integer.cpp(54): error C2682: cannot use dynamic_cast to convert from 'const NodeItem' to 'Integer &'
I'm not too sure of another way of doing this, but basically I want the function to be able to take a NodeItem pointer, and check whether the NodeItem is an Integer by using dynamic_cast and testing for a NULL result.
Thanks for the help in advance.
Here, take a look:
int Integer::compareTo(const NodeItem &anotherNodeItem)
{
int returnCode = 0;
Integer *otherInteger = dynamic_cast<Integer&>(anotherNodeItem);
if (otherInteger == NULL)
returnCode = ERROR_INCOMPATIBLE_TYPES;
else
returnCode = compareTo(*otherInteger);
delete otherInteger;
return returnCode;
}
The error I get when I try to compile is at this statement:
Integer *otherInteger = dynamic_cast<Integer&>(anotherNodeItem);
The error is this:
Integer.cpp(54): error C2682: cannot use dynamic_cast to convert from 'const NodeItem' to 'Integer &'
I'm not too sure of another way of doing this, but basically I want the function to be able to take a NodeItem pointer, and check whether the NodeItem is an Integer by using dynamic_cast and testing for a NULL result.
Thanks for the help in advance.