Thread: iso c++ forbids forward references to 'enum'

  1. #1
    Registered User
    Join Date
    Jun 2018
    Posts
    5

    iso c++ forbids forward references to 'enum'

    Hi,

    I am still getting to know native code.

    I am trying to include libswscale into my c++ project using extern C like I have already with libavcodec but the compiler complains of an error in swscale.h when I include in my c++ file - I have tried to use a c file as well but it tells me iso c++ forbids forward references to 'enum' because some of the function declarations in the header file contain references to enum.

    My own research suggests it may have something to do with using c++11 which I think I am using in my project.

    Is there anything I can do to fix this and include swscale.h without errors so I can resize an AVFrame* in my project using libswscale?

    My project is a Tizen app with a native module and seems to have to use flags -c and -std=gnu++11 to compile without errors usually.

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    3,687
    Is there a reason you can not just include the header file instead of using forward references?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Jun 2018
    Posts
    5
    Thanks for your response.

    I am including the swscale.h header file (by linking the folder which includes third party header files I use). It just errors when building and show some functions in that header file as invalid because of the enums being passed in the functions - a example function in that header file is below..




    Code:
    int sws_isSupportedOutput(enum  pix_fmt);

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,235
    What exactly is the relevant error message?

    The enum type would be defined somewhere, so basically you need to include whichever header defines it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jun 2018
    Posts
    5
    Hi,

    The error when I include swscale.h and try to use a function in it is

    third_party/include/libswscale/swscale.h:205:60: error: ISO C++ forbids forward references to 'enum' types
    struct SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat,
    ^

  6. #6
    Registered User
    Join Date
    Jun 2018
    Posts
    5
    I have just noticed If I try to build still including the library without using the function or including the header I get an error about the library telling me I must use --pnacl-allow-native

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,235
    The "forward declaration" is probably because syntax like this:
    Code:
    enum  pix_fmt;
    would be a forward declaration of pix_fmt as an enum type. So it remains: you need to include the header in which this enum type is defined.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Jun 2018
    Posts
    5
    Thanks for that answer, it helped fix the problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Forbids Declaration of '___' with no type
    By warfang in forum C++ Programming
    Replies: 6
    Last Post: 03-26-2007, 11:01 PM
  2. ISO C++ Forbids it!
    By Jimmey in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 05:40 PM
  3. ISO C++ forbids declaration of
    By bhorrobi in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2003, 03:36 PM
  4. declare references to references works!
    By ManuelH in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2003, 08:14 AM
  5. Forbids Declaration with No Type
    By ProgrammingDlux in forum C++ Programming
    Replies: 6
    Last Post: 03-24-2002, 07:39 PM

Tags for this Thread