Now I have two VC projects: A and B. I'm working with Project B, I need to use an enum
type defined in a header file in Project A, I cannot include this header file.
Can I use extern
to extend the visibility of the enum type to Project B?
If so, how can I do it? And if not, is there any other way to use this enum
type in Project B?
Can I use extern to extend the visibility of the enum type to Project B?
No. The definition of an enumeration is needed in any translation unit that uses it.
Is there any other ways to use this enum type in Project B?
No. Your only options are to make the header in A available to B, or copy the definition and find some way to keep the copies consistent.
extern only tells the compiler that the definition for a particular symbol is some other file the current one you only have the declaration. This the mechanism you use to make global variable visible in your source code. So for your case, extern will not do.
what you can do is have a common header file for both project and in there:
typedef enum{
...
//enum members
...
};
This way both project can use the same enum.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With