CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Oct 2004
    Posts
    21

    Question Error when trying to dynamic_cast<> a reference of a variable

    Hi, I am trying to create a function that compare's two objects.

    Here, take a look:
    Code:
    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:
    Code:
    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.
    Last edited by johnnyICON; March 13th, 2005 at 05:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured