0

Enum:

    enum DataStatus
    {
        DataNotAvailable = -1,
        DataLocallyAvailable = 0,
        DataExternallyAvailable = 1,
    };

Function definition:

    GetDataStatusByFrame(UINT PI_uiRequestFrameNo, DataStatus *PO_peDataStatus);

Comparsion:

    IDataHandler::DataStatus* pinnedPointer = new IDataHandler::DataStatus();
    GetDataStatusByFrame(1, pinnedPointer);

    if (pinnedPointer == IDataHandler::DataStatus::DataNotAvailable) // 'cannot convert' exception
    {
      // ...
    }

Question:

How can i compare these types or at least cast them to the same datatype?

2
  • 2
    Can you not just dereference the pointer? Commented Mar 19, 2012 at 11:32
  • 2
    Maybe you could do with some back to basics information. Consider reading about pointers in your favorite book. Commented Mar 19, 2012 at 12:15

4 Answers 4

4

This API looks like it is intended to be called in a slightly simpler manner to avoid dynamically allocating memory that you need to clean up later. Just put the variable on the stack and it will be cleaned up automatically;

IDataHandler::DataStatus status;

GetDataStatusByFrame(1, &status);

if (status == IDataHandler::DataStatus::DataNotAvailable) // 'cannot convert' exception
{
  // ...
}
Sign up to request clarification or add additional context in comments.

Comments

3

Use

if (*pinnedPointer == IDataHandler::DataStatus::DataNotAvailable)

Comments

3
if (*pinnedPointer == IDataHandler::DataStatus::DataNotAvailable)
{
    //...
}

Comments

1

Is the allocation necessary? Why not do the following instead?

IDataHandler::DataStatus status;
GetDataStatusByFrame(1, &status);
if (status == IDataHandler::DataStatus::DataNotAvailable) {
    // ...
}

It is very rare to allocate to an enum pointer. Usually you pass the address of a statically allocated variable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.