Thread: Inconsistent errors - MSVC++ 6

  1. #1
    Registered User AeroHammer's Avatar
    Join Date
    Sep 2002
    Posts
    12

    Angry Inconsistent errors - MSVC++ 6

    Okay, here's the pronlem:

    I have some image editing code, that totals up to 15 different functions. All of these functions use a class called rgb. Class rgb has the following members:
    r
    g
    b
    s

    Now, for some reason, sometimes when I try to use an rgb class, I can't access these variables, despite the fact that they're public for simplicity. Here's a declaration of a function that can access them:

    Code:
    AndMaps( rgb src[], rgb trgt[], long pixels )
    And here's an example of one that can't use the members:

    Code:
    TraMaps( rgb src[], rgb Faded, double fade, long pixels )
    Now, I can't see any differences between these that should cause problems. However, just to be safe, here's the error messages:

    --------------------Configuration: Image Operations 2 - Win32 Debug--------------------
    Compiling...
    RGB_Operations.cpp
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(129) : error C2228: left of '.b' must have class/struct/union type
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(130) : error C2228: left of '.g' must have class/struct/union type
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(131) : error C2228: left of '.r' must have class/struct/union type
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(145) : warning C4804: '<' : unsafe use of type 'bool' in operation
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(145) : warning C4804: '<' : unsafe use of type 'bool' in operation
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(145) : error C2228: left of '.r' must have class/struct/union type
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(147) : error C2228: left of '.b' must have class/struct/union type
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(149) : warning C4804: '>' : unsafe use of type 'bool' in operation
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(149) : warning C4804: '>' : unsafe use of type 'bool' in operation
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(149) : error C2228: left of '.r' must have class/struct/union type
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(151) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class rgb' (or there is no acceptable conv
    ersion)
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(165) : error C2676: binary '!=' : 'class rgb' does not define this operator or a conversion to a type acceptable to the predefined operat
    or
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(232) : error C2676: binary '[' : 'class rgb' does not define this operator or a conversion to a type acceptable to the predefined operato
    r
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(232) : error C2228: left of '.b' must have class/struct/union type
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(233) : error C2676: binary '[' : 'class rgb' does not define this operator or a conversion to a type acceptable to the predefined operato
    r
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(233) : error C2228: left of '.g' must have class/struct/union type
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(234) : error C2676: binary '[' : 'class rgb' does not define this operator or a conversion to a type acceptable to the predefined operato
    r
    C:\Documents and Settings\Owner\My Documents\My Files\Programming\C++\BMP Actions\BMP Editor\RGB_Operations.cpp(234) : error C2228: left of '.r' must have class/struct/union type
    Error executing cl.exe.

    RGB_Operations.obj - 14 error(s), 4 warning(s)
    I realize that some of the stuff I'll need to deal with anyways, like the = and -= operators, but I decided to give you the entire message. So, can you guys tell me what to do? I'm kinda stuck here.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    "Now, I can't see any differences between these that should cause problems."

    One of the problems you might have has to do with the difference between passing by value and passing by reference, but from the errors it looks like you aren't using the proper names of the objects when you use the direct member access operator(.).

    For this function:

    TraMaps( rgb src[], rgb Faded, double fade, long pixels )

    you have to access the members like this:

    src[1].r

    or

    Faded.r

    If you are trying something like:

    fade.r

    or

    pixels.r

    or as indicated by the error message:

    error C2676: binary '[' : 'class rgb' does not define this operator or a conversion to a type acceptable to the predefined operato
    r

    Faded[1].r



    you will get those errors.
    Last edited by 7stud; 05-05-2003 at 10:56 PM.

  3. #3
    Registered User AeroHammer's Avatar
    Join Date
    Sep 2002
    Posts
    12

    Cool

    Thanks, that cleared it up. I think I was too close to the coding to see it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. MSVC Template Constructor/Assignment Errors
    By LuckY in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 02:57 PM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. MSVC 6 SP5 template errors
    By jdinger in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2003, 09:59 AM
  5. odd errors from msvc std library files
    By blight2c in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2002, 12:06 AM