ARC and reinterpret_cast?

  • Hi. I'd like to write code like this:

    MyObject* foo = reinterpret_cast<__bridge MyObject*> (someVoidPointer);

    But the compiler doesn't like it. It's perfectly happy with:

    MyObject* foo = (__bridge MyObject) someVoidPointer;

    this is in a .mm file.

    The error is:

    error: type name requires a specifier or qualifier
            MyObject* me = reinterpret_cast<__bridge MyObject*> (inRefCon);
                                            ^
    error: expected '>'
            MyObject* me = reinterpret_cast<__bridge MyObject*> (inRefCon);
                                            ^
                                            >
    note: to match this '<'
            MyObject* me = reinterpret_cast<__bridge MyObject*> (inRefCon);
                                          ^
    Is it a bug in the compiler, or am I doing something wrong?

    TIA,
    --
    Rick
  • On 08.07.2012, at 06:13, Rick Mann wrote:

    > Hi. I'd like to write code like this:
    >
    > MyObject* foo = reinterpret_cast<__bridge MyObject*> (someVoidPointer);
    >
    > But the compiler doesn't like it. It's perfectly happy with:
    >
    > MyObject* foo = (__bridge MyObject) someVoidPointer;
    >
    > this is in a .mm file.

    You probably meant this (without typo):
    > MyObject* foo = (__bridge MyObject*) someVoidPointer;

    I think, the assumption that __bridge is a simple type qualifier (like const or volatile) is false. It's rather a type conversion operator returning an object akin to an instance of a non-POD type.

    What you are seeking for would be probably this:

    MyObject* foo = __bridge_cast<MyObject*>(someVoidPointer);

    But this doesn't exist - unless you define it yourself  ;)

    Andreas

    >
    > The error is:
    >
    > error: type name requires a specifier or qualifier
    > MyObject* me = reinterpret_cast<__bridge MyObject*> (inRefCon);
    > ^
    > error: expected '>'
    > MyObject* me = reinterpret_cast<__bridge MyObject*> (inRefCon);
    > ^
    >>
    > note: to match this '<'
    > MyObject* me = reinterpret_cast<__bridge MyObject*> (inRefCon);
    > ^
    > Is it a bug in the compiler, or am I doing something wrong?
    >
    > TIA,
    > --
    > Rick
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today