Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. error C2678

error C2678

Scheduled Pinned Locked Moved C / C++ / MFC
linuxregexhelplearning
30 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I've met a weird error:

    error C2678: binary '|=' : no operator found which takes a left-hand operand of type 'FILE_ATTR_FLAGS' (or there is no acceptable conversion)

    1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\propsys.h(703): could be 'GETPROPERTYSTOREFLAGS &operator |=(GETPROPERTYSTOREFLAGS &,GETPROPERTYSTOREFLAGS)'
    1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\propsys.h(1685): or 'PROPDESC_TYPE_FLAGS &operator |=(PROPDESC_TYPE_FLAGS &,PROPDESC_TYPE_FLAGS)'
    1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\propsys.h(1704): or 'PROPDESC_VIEW_FLAGS &operator |=(PROPDESC_VIEW_FLAGS &,PROPDESC_VIEW_FLAGS)'
    ........
    ........
    1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(31763): or 'HOMEGROUPSHARINGCHOICES &operator |=(HOMEGROUPSHARINGCHOICES &,HOMEGROUPSHARINGCHOICES)'
    1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(32037): or 'LIBRARYOPTIONFLAGS &operator |=(LIBRARYOPTIONFLAGS &,LIBRARYOPTIONFLAGS)'
    1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(32052): or 'LIBRARYSAVEFLAGS &operator |=(LIBRARYSAVEFLAGS &,LIBRARYSAVEFLAGS)'
    1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(32793): or 'LIBRARYMANAGEDIALOGOPTIONS &operator |=(LIBRARYMANAGEDIALOGOPTIONS &,LIBRARYMANAGEDIALOGOPTIONS)'
    1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\thumbcache.h(119): or 'WTS_FLAGS &operator |=(WTS_FLAGS &,WTS_FLAGS)'
    1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\thumbcache.h(127): or 'WTS_CACHEFLAGS &operator |=(WTS_CACHEFLAGS &,WTS_CACHEFLAGS)'
    1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shlobj.h(542): or 'SHELL_LINK_DATA_FLAGS &operator |=(SHELL_LINK_DATA_FLAGS &,SHELL_LINK_DATA_FLAGS)'
    1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shlobj.h(1394): or 'KNOWN_FOLDER_FLAG &operator |=(KNOWN_FOLDER_FLAG &,KNOWN_FOLDER_FLAG)'
    1> while trying to match the argument list '(FILE_FLAGS, FILE_FLAGS)'

    Here is the code that generate the error:

    sc->flags |= flag;

    where flag is FILE_FLAGS, and sc->flags is

    struct scr {
    ....
    ....
    FILE_FLAGS flags;
    ....
    };

    Now, of course that I'ave tried:

    scr& operator|=(const scr& rhs)
    {
    	return \*this;
    }
    

    but this err

    L 1 Reply Last reply
    0
    • _ _Flaviu

      I've met a weird error:

      error C2678: binary '|=' : no operator found which takes a left-hand operand of type 'FILE_ATTR_FLAGS' (or there is no acceptable conversion)

      1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\propsys.h(703): could be 'GETPROPERTYSTOREFLAGS &operator |=(GETPROPERTYSTOREFLAGS &,GETPROPERTYSTOREFLAGS)'
      1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\propsys.h(1685): or 'PROPDESC_TYPE_FLAGS &operator |=(PROPDESC_TYPE_FLAGS &,PROPDESC_TYPE_FLAGS)'
      1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\propsys.h(1704): or 'PROPDESC_VIEW_FLAGS &operator |=(PROPDESC_VIEW_FLAGS &,PROPDESC_VIEW_FLAGS)'
      ........
      ........
      1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(31763): or 'HOMEGROUPSHARINGCHOICES &operator |=(HOMEGROUPSHARINGCHOICES &,HOMEGROUPSHARINGCHOICES)'
      1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(32037): or 'LIBRARYOPTIONFLAGS &operator |=(LIBRARYOPTIONFLAGS &,LIBRARYOPTIONFLAGS)'
      1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(32052): or 'LIBRARYSAVEFLAGS &operator |=(LIBRARYSAVEFLAGS &,LIBRARYSAVEFLAGS)'
      1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shobjidl.h(32793): or 'LIBRARYMANAGEDIALOGOPTIONS &operator |=(LIBRARYMANAGEDIALOGOPTIONS &,LIBRARYMANAGEDIALOGOPTIONS)'
      1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\thumbcache.h(119): or 'WTS_FLAGS &operator |=(WTS_FLAGS &,WTS_FLAGS)'
      1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\thumbcache.h(127): or 'WTS_CACHEFLAGS &operator |=(WTS_CACHEFLAGS &,WTS_CACHEFLAGS)'
      1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shlobj.h(542): or 'SHELL_LINK_DATA_FLAGS &operator |=(SHELL_LINK_DATA_FLAGS &,SHELL_LINK_DATA_FLAGS)'
      1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\shlobj.h(1394): or 'KNOWN_FOLDER_FLAG &operator |=(KNOWN_FOLDER_FLAG &,KNOWN_FOLDER_FLAG)'
      1> while trying to match the argument list '(FILE_FLAGS, FILE_FLAGS)'

      Here is the code that generate the error:

      sc->flags |= flag;

      where flag is FILE_FLAGS, and sc->flags is

      struct scr {
      ....
      ....
      FILE_FLAGS flags;
      ....
      };

      Now, of course that I'ave tried:

      scr& operator|=(const scr& rhs)
      {
      	return \*this;
      }
      

      but this err

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Where is FILE_FLAGS defined? IN your code, or in a system header?

      _ 1 Reply Last reply
      0
      • L Lost User

        Where is FILE_FLAGS defined? IN your code, or in a system header?

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        Is defined inside of one of my code header:

        typedef enum {
        FILE_READONLY = 0x00000001,
        FILE_HIDDEN = 0x00000002,
        FILE_SYSTEM = 0x00000004,

        FILE\_DIRECTORY = 0x00000010,
        FILE\_ARCHIVE = 0x00000020,
        FILE\_DEVICE = 0x00000040,
        FILE\_NORMAL = 0x00000080,
        
        FILE\_TEMPORARY = 0x00000100,
        

        ....
        .....

        }FILE_FLAGS;

        L 1 Reply Last reply
        0
        • _ _Flaviu

          Is defined inside of one of my code header:

          typedef enum {
          FILE_READONLY = 0x00000001,
          FILE_HIDDEN = 0x00000002,
          FILE_SYSTEM = 0x00000004,

          FILE\_DIRECTORY = 0x00000010,
          FILE\_ARCHIVE = 0x00000020,
          FILE\_DEVICE = 0x00000040,
          FILE\_NORMAL = 0x00000080,
          
          FILE\_TEMPORARY = 0x00000100,
          

          ....
          .....

          }FILE_FLAGS;

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          This works but is not really correct.

          sc->flags = FILE_FLAGS(sc->flags | flag);

          I suspect the issue is that enums are usually used to signify single values, i.e the flags field is either FILE_READONLY or FILE_SYSTEM, but not both. If you need to combine values then you should really use a set of #define statements.

          _ 1 Reply Last reply
          0
          • L Lost User

            This works but is not really correct.

            sc->flags = FILE_FLAGS(sc->flags | flag);

            I suspect the issue is that enums are usually used to signify single values, i.e the flags field is either FILE_READONLY or FILE_SYSTEM, but not both. If you need to combine values then you should really use a set of #define statements.

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #5

            Thank you Richard, that error has vanished, but I cannot try this code yet ... why do you say that this solution is not really correct ? The safe solution would be to overload |= operator, but I cannot do that into enum, right ?

            L 1 Reply Last reply
            0
            • _ _Flaviu

              Thank you Richard, that error has vanished, but I cannot try this code yet ... why do you say that this solution is not really correct ? The safe solution would be to overload |= operator, but I cannot do that into enum, right ?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              _Flaviu wrote:

              why do you say that this solution is not really correct ?

              Because, as I mentioned before, enums are used to indicate a set of possible values for an item. For example a class of type Car could contain an enum that indicates the manufacturer, such that the enum definition is:

              enum manufacturer
              {
              AUDI = 1,
              BMW,
              DAIMLER,
              MERCEDES,
              // etc.
              }

              And you would never combine thos values in the car type variable. So, in your case you should use #define statements, which the compiler will be happy with.

              _ 1 Reply Last reply
              0
              • L Lost User

                _Flaviu wrote:

                why do you say that this solution is not really correct ?

                Because, as I mentioned before, enums are used to indicate a set of possible values for an item. For example a class of type Car could contain an enum that indicates the manufacturer, such that the enum definition is:

                enum manufacturer
                {
                AUDI = 1,
                BMW,
                DAIMLER,
                MERCEDES,
                // etc.
                }

                And you would never combine thos values in the car type variable. So, in your case you should use #define statements, which the compiler will be happy with.

                _ Offline
                _ Offline
                _Flaviu
                wrote on last edited by
                #7

                But this enum is not a part of any struct or class, is just defined into a header file, along with other several enum's ... and this enum has a lot of values, that is why I intend to avoid to translated as #define's ... I don't know what to do ...

                L 1 Reply Last reply
                0
                • _ _Flaviu

                  But this enum is not a part of any struct or class, is just defined into a header file, along with other several enum's ... and this enum has a lot of values, that is why I intend to avoid to translated as #define's ... I don't know what to do ...

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  But the issue is, as I keep repeating, that this is not the correct way to use enums. If you want to combine flag values then use #define, if you want to select one value from a set then use enum. That is the rule for C and C++, and that is why the compiler complains about your code.

                  _ 1 Reply Last reply
                  0
                  • L Lost User

                    But the issue is, as I keep repeating, that this is not the correct way to use enums. If you want to combine flag values then use #define, if you want to select one value from a set then use enum. That is the rule for C and C++, and that is why the compiler complains about your code.

                    _ Offline
                    _ Offline
                    _Flaviu
                    wrote on last edited by
                    #9

                    Thank you Richard for your patience. BTW, is a legacy code, is not written by me. There will be more suitable to chnage this enum to a struct and where to overload |= operator ?

                    L 1 Reply Last reply
                    0
                    • _ _Flaviu

                      Thank you Richard for your patience. BTW, is a legacy code, is not written by me. There will be more suitable to chnage this enum to a struct and where to overload |= operator ?

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Why would you change it to a struct, it only requires a single integer variable to hold all the flags.

                      int flags = FILE_READONLY | FILE_HIDDEN;
                      flags |= FILE_SYSTEM;

                      _ 2 Replies Last reply
                      0
                      • L Lost User

                        Why would you change it to a struct, it only requires a single integer variable to hold all the flags.

                        int flags = FILE_READONLY | FILE_HIDDEN;
                        flags |= FILE_SYSTEM;

                        _ Offline
                        _ Offline
                        _Flaviu
                        wrote on last edited by
                        #11

                        So the finest solution is to take these values from enum and put them as #defines. I will do this change.

                        1 Reply Last reply
                        0
                        • L Lost User

                          Why would you change it to a struct, it only requires a single integer variable to hold all the flags.

                          int flags = FILE_READONLY | FILE_HIDDEN;
                          flags |= FILE_SYSTEM;

                          _ Offline
                          _ Offline
                          _Flaviu
                          wrote on last edited by
                          #12

                          I am afraid that I cannot change that enum into #defines, because I have:

                          na->flags |= flag;

                          where

                          FILE_FLAGS flag;

                          and na is struct level1, and inside this level1 struct, I have

                          struct level1
                          {
                          FILE_FLAGS flags;
                          ....
                          };

                          I have entered in some deadlock ? Please help me to solve this error ...

                          V L 2 Replies Last reply
                          0
                          • _ _Flaviu

                            I am afraid that I cannot change that enum into #defines, because I have:

                            na->flags |= flag;

                            where

                            FILE_FLAGS flag;

                            and na is struct level1, and inside this level1 struct, I have

                            struct level1
                            {
                            FILE_FLAGS flags;
                            ....
                            };

                            I have entered in some deadlock ? Please help me to solve this error ...

                            V Offline
                            V Offline
                            Victor Nijegorodov
                            wrote on last edited by
                            #13

                            Try to declare both flags and flag as int

                            _ 1 Reply Last reply
                            0
                            • V Victor Nijegorodov

                              Try to declare both flags and flag as int

                              _ Offline
                              _ Offline
                              _Flaviu
                              wrote on last edited by
                              #14

                              Yes, but FILE_FLAGS is enum with int values ...

                              V 1 Reply Last reply
                              0
                              • _ _Flaviu

                                Yes, but FILE_FLAGS is enum with int values ...

                                V Offline
                                V Offline
                                Victor Nijegorodov
                                wrote on last edited by
                                #15

                                Then, as Richard already suggested replace this enum with a set of #define.

                                _ 1 Reply Last reply
                                0
                                • V Victor Nijegorodov

                                  Then, as Richard already suggested replace this enum with a set of #define.

                                  _ Offline
                                  _ Offline
                                  _Flaviu
                                  wrote on last edited by
                                  #16

                                  Agree, but that enum is a part of another struct ... so, how can I put as part of a struct several #defines ?

                                  1 Reply Last reply
                                  0
                                  • _ _Flaviu

                                    I am afraid that I cannot change that enum into #defines, because I have:

                                    na->flags |= flag;

                                    where

                                    FILE_FLAGS flag;

                                    and na is struct level1, and inside this level1 struct, I have

                                    struct level1
                                    {
                                    FILE_FLAGS flags;
                                    ....
                                    };

                                    I have entered in some deadlock ? Please help me to solve this error ...

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #17

                                    Of course you can change it to #defines. The definition of FILE_FLAGS then becomes an int type. And then the rest of the code should compile correctly.

                                    _ 1 Reply Last reply
                                    0
                                    • L Lost User

                                      Of course you can change it to #defines. The definition of FILE_FLAGS then becomes an int type. And then the rest of the code should compile correctly.

                                      _ Offline
                                      _ Offline
                                      _Flaviu
                                      wrote on last edited by
                                      #18

                                      I am not get something, so forgive me. I have moved those enum values as #defines, but of course, now I get error from struct: doesn't know who is FILE_FLAGS flags; from level1 struct.

                                      /*
                                      typedef enum {
                                      FILE_READONLY = 0x00000001,
                                      FILE_HIDDEN = 0x00000002,
                                      FILE_SYSTEM = 0x00000004,

                                      FILE\_DIRECTORY = 0x00000010,
                                      FILE\_ARCHIVE = 0x00000020,
                                      FILE\_DEVICE = 0x00000040,
                                      FILE\_NORMAL = 0x00000080,
                                      
                                      FILE\_TEMPORARY = 0x00000100,
                                      

                                      ....
                                      .....

                                      }FILE_FLAGS;
                                      */

                                      #define FILE_READONLY = 0x00000001
                                      #define FILE_HIDDEN = 0x00000002
                                      #define FILE_SYSTEM = 0x00000004

                                      of course, FILE_FLAGS enum has disappeared ... obviously, I don't understood something ... but what ?

                                      struct level1
                                      {
                                      FILE_FLAGS flags; // <-- error
                                      ....
                                      };

                                      V L 2 Replies Last reply
                                      0
                                      • _ _Flaviu

                                        I am not get something, so forgive me. I have moved those enum values as #defines, but of course, now I get error from struct: doesn't know who is FILE_FLAGS flags; from level1 struct.

                                        /*
                                        typedef enum {
                                        FILE_READONLY = 0x00000001,
                                        FILE_HIDDEN = 0x00000002,
                                        FILE_SYSTEM = 0x00000004,

                                        FILE\_DIRECTORY = 0x00000010,
                                        FILE\_ARCHIVE = 0x00000020,
                                        FILE\_DEVICE = 0x00000040,
                                        FILE\_NORMAL = 0x00000080,
                                        
                                        FILE\_TEMPORARY = 0x00000100,
                                        

                                        ....
                                        .....

                                        }FILE_FLAGS;
                                        */

                                        #define FILE_READONLY = 0x00000001
                                        #define FILE_HIDDEN = 0x00000002
                                        #define FILE_SYSTEM = 0x00000004

                                        of course, FILE_FLAGS enum has disappeared ... obviously, I don't understood something ... but what ?

                                        struct level1
                                        {
                                        FILE_FLAGS flags; // <-- error
                                        ....
                                        };

                                        V Offline
                                        V Offline
                                        Victor Nijegorodov
                                        wrote on last edited by
                                        #19

                                        _Flaviu wrote:

                                        struct level1 { FILE_FLAGS flags; // <-- error .... };

                                        Try

                                        struct level1
                                        {
                                        int flags; // <-- error
                                        ....
                                        };

                                        _ 1 Reply Last reply
                                        0
                                        • V Victor Nijegorodov

                                          _Flaviu wrote:

                                          struct level1 { FILE_FLAGS flags; // <-- error .... };

                                          Try

                                          struct level1
                                          {
                                          int flags; // <-- error
                                          ....
                                          };

                                          _ Offline
                                          _ Offline
                                          _Flaviu
                                          wrote on last edited by
                                          #20

                                          Ok, but even flag is comming as function parameter, just like this:

                                          static void SomeFunction(level1* na, FILE_FLAGS flag)
                                          {
                                          ....
                                          na->flags |= ~flag;
                                          ....
                                          }

                                          So, I guess I cannot give up FILE_FLAGS enum ... don't I ?

                                          V 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups