Declaration of @class equivalent for a struct

Nicolas Manzini

I would like to avoid importing AVFoundation framework in my header but I need to declare CMTime.

For NSObject I can do @class AVPlayer; and import everything in the .m file. How to do this with a struct like CMTime?

Sergey Kalinichenko

If you need to reference CMTime struct in the header, you need to include <CMTime.h>: forward-declaring a struct lets you use the name of the type in declarations of pointers, but not in declarations of members of that struct type.

In other words, you can do this:

struct CMTime; // Forward declaration of the struct

@interface MyInterface : NSObject
-(void)fillCmTime:(CMTime*)buffer;
@end

but you cannot do this:

struct CMTime; // Forward declaration of the struct
@interface MyInterface : NSObject {
    // This is not allowed
    CMTime time;
}
// This is not allowed either
-(CMTime)getTime;
@end

The reason that you can do @class AVPlayer and then use it in declarations of members is that Objective-C classes (id-types) are implemented as pointers. In fact, you cannot declare variables of an id-type without an asterisk.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

class/struct design; inheritance vs forward declaration

From Dev

class/struct design; inheritance vs forward declaration

From Dev

invalid token ';' in class struct or interface member declaration

From Dev

Pack = 4 and Pack = 1 makes the struct not equivalent to its C declaration

From Dev

"warning: useless storage class specifier in empty declaration" in struct

From Dev

Why is a class/struct declaration with different number of template parameters not allowed?

From Dev

Invalid token '=' in class, struct, or interface member declaration c#

From Dev

Invalid token 'event' in class, record, struct, or interface member declaration

From Dev

Why is a class/struct declaration with different number of template parameters not allowed?

From Dev

"warning: useless storage class specifier in empty declaration" in struct

From Dev

Using Reflection to copy across equivalent properties between struct and class

From Dev

Using Reflection to copy across equivalent properties between struct and class

From Dev

Struct declaration order

From Dev

Unsized array declaration in a struct

From Dev

struct accessible without declaration?

From Dev

Unsized array declaration in a struct

From Dev

Pointer declaration with and without struct?

From Dev

ASP.NET: CS1519: Invalid token 'this' in class, struct, or interface member declaration

From Dev

c# Invalid token 'while' in class, struct, or interface member declaration (while loop not working)

From Dev

Can I access a static member function on a class/struct which I don't have any forward declaration?

From Dev

C++: &*A is not equivalent to A for array declaration?

From Dev

Equivalent of C extern declaration in JavaScript

From Dev

Class declaration within a function declaration

From Dev

Forward Struct Declaration in C; not working

From Dev

Declaration of inner struct in another struct results in error: invalid use of struct

From Dev

Class' Struct's function declaration in header and definition in cpp. lnk2019 when using function in separate lib

From Dev

AVPlayer forward class declaration

From Dev

Class or enumeration using declaration

From Dev

Is class member declaration not a statement?

Related Related

  1. 1

    class/struct design; inheritance vs forward declaration

  2. 2

    class/struct design; inheritance vs forward declaration

  3. 3

    invalid token ';' in class struct or interface member declaration

  4. 4

    Pack = 4 and Pack = 1 makes the struct not equivalent to its C declaration

  5. 5

    "warning: useless storage class specifier in empty declaration" in struct

  6. 6

    Why is a class/struct declaration with different number of template parameters not allowed?

  7. 7

    Invalid token '=' in class, struct, or interface member declaration c#

  8. 8

    Invalid token 'event' in class, record, struct, or interface member declaration

  9. 9

    Why is a class/struct declaration with different number of template parameters not allowed?

  10. 10

    "warning: useless storage class specifier in empty declaration" in struct

  11. 11

    Using Reflection to copy across equivalent properties between struct and class

  12. 12

    Using Reflection to copy across equivalent properties between struct and class

  13. 13

    Struct declaration order

  14. 14

    Unsized array declaration in a struct

  15. 15

    struct accessible without declaration?

  16. 16

    Unsized array declaration in a struct

  17. 17

    Pointer declaration with and without struct?

  18. 18

    ASP.NET: CS1519: Invalid token 'this' in class, struct, or interface member declaration

  19. 19

    c# Invalid token 'while' in class, struct, or interface member declaration (while loop not working)

  20. 20

    Can I access a static member function on a class/struct which I don't have any forward declaration?

  21. 21

    C++: &*A is not equivalent to A for array declaration?

  22. 22

    Equivalent of C extern declaration in JavaScript

  23. 23

    Class declaration within a function declaration

  24. 24

    Forward Struct Declaration in C; not working

  25. 25

    Declaration of inner struct in another struct results in error: invalid use of struct

  26. 26

    Class' Struct's function declaration in header and definition in cpp. lnk2019 when using function in separate lib

  27. 27

    AVPlayer forward class declaration

  28. 28

    Class or enumeration using declaration

  29. 29

    Is class member declaration not a statement?

HotTag

Archive