На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
Модераторы: Qraizer, Hsilgos
  
> ничего не понммаю. , перекрестное определение
    поскажите, как вот это заставить работать. есть две структуры:

    struct Color_32;
    struct _Color1555;
    typedef unsigned int  uint32_t;
    typedef signed  int int32_t;
    typedef short unsigned int uint16_t;
    typedef unsigned char  uint8_t;
    struct Color_32
    {
    typedef uint8_t _T;
    enum {maxValue = 255};
    _T r, g, b, a;

    Color_32 &operator =( const _Color1555 & A)
    {
     a =   (A.value & 0x8000) ? 255 : 0;
     r =   ((A.value & 0x7C00) >> 7);
     g =   ((A.value & 0x3E0 ) >> 2);
     b =   ((A.value & 0x1F  ) << 3);
     return *this;
    }

    uint32_t GetColor()
    {
     uint32_t c = 0;
     c |= (((uint32_t)b) << 16) | (((uint32_t)g) << 8) | ((uint32_t)r);
     return c;
    }
    };

    struct _Color1555
    {
    unsigned short value;
    _Color1555& operator =( const Color_32 & A )
    {
     value = ((A.a >> 7) << 15) + ((A.r >> 3) << 10) + ((A.g >> 3) << 5) + (A.b >> 3);
     return *this;
    }
    };

    похоже, что из-за того, что они друг на друга ссылаются нифига компилится не хочет. что делать? unsure.gif
    Сообщение отредактировано: experimenter -
      Цитата
      что они друг на друга ссылаются нифига компилится не хочет


      1) кто на кого ссылается
      2) что за ошибка выдается и где
        Цитата (Uncle_Bob @ 21.11.03, 17:26)
        Цитата
        что они друг на друга ссылаются нифига компилится не хочет


        1) кто на кого ссылается
        2) что за ошибка выдается и где

        struct Color_32 ccылается на struct _Color1555 и наоборот, причем оба в перегруженных операторах operator =. ошибок выдает море:
        Цитата

        : error C2027: use of undefined type '_Color1555'
        hpp(20) : see declaration of '_Color1555'
        : error C2228: left of '.value' must have class/struct/union typ
        : error C2027: use of undefined type '_Color1555'
        hpp(20) : see declaration of '_Color1555'
        : error C2228: left of '.value' must have class/struct/union typ
        : error C2027: use of undefined type '_Color1555'
        hpp(20) : see declaration of '_Color1555'
        : error C2228: left of '.value' must have class/struct/union typ
        : error C2027: use of undefined type '_Color1555'
        hpp(20) : see declaration of '_Color1555'
        : error C2228: left of '.value' must have class/struct/union typ

        error C2027: use of undefined type '_Color1555'
        p(20) : see declaration of '_Color1555'
        error C2228: left of '.value' must have class/struct/union type
        error C2027: use of undefined type '_Color1555'
        p(20) : see declaration of '_Color1555'
        error C2228: left of '.value' must have class/struct/union type
        error C2027: use of undefined type '_Color1555'
        p(20) : see declaration of '_Color1555'
        error C2228: left of '.value' must have class/struct/union type
        error C2027: use of undefined type '_Color1555'
        p(20) : see declaration of '_Color1555'
        error C2228: left of '.value' must have class/struct/union type

        если убрать вот эти два определения

        struct Color_32;
        struct _Color1555;

        то выдает следующие ошибки:
        Цитата

        : error C2143: syntax error : missing ',' before '&'
        : error C2059: syntax error : '&'

        error C2143: syntax error : missing ',' before '&'
        error C2059: syntax error : '&'

        первые две ошибки (C2143,C2059)указывают на перегруженный оператор в структуре _Color1555, а вторые на Color_32.
          Так конечно не получится, потому как для Color_32 Color_1555 не имеет еще мембера value потому и не работает. Попробуй функции продефинировать в отдельном cpp файле. Дай компайлеру сначала разобраться со структурами, а потом с кодом.

          Тоесть

          Хидер


          struct Color_32;
          struct _Color1555;

          typedef unsigned int  uint32_t;
          typedef signed  int int32_t;
          typedef short unsigned int uint16_t;
          typedef unsigned char  uint8_t;

          struct Color_32
          {
          typedef uint8_t _T;
          enum {maxValue = 255};

          _T r, g, b, a;

          Color_32 &operator =( const _Color1555 & A)

          uint32_t GetColor()
          {
           uint32_t c = 0;
           c |= (((uint32_t)b) << 16) | (((uint32_t)g) << 8) | ((uint32_t)r);
           return c;
          }
          };


          struct _Color1555
          {
          unsigned short value;

          _Color1555& operator =( const Color_32 & A );
          };



          и CPP файл

          #include "Хидер.h"

          Color_32& Color_32::operator =( const _Color1555 & A)
          {
          a =   (A.value & 0x8000) ? 255 : 0;
          r =   ((A.value & 0x7C00) >> 7);
          g =   ((A.value & 0x3E0 ) >> 2);
          b =   ((A.value & 0x1F  ) << 3);
          return *this;
          }

          _Color1555& _Color1555::operator =( const Color_32 & A )
          {
          value = ((A.a >> 7) << 15) + ((A.r >> 3) << 10) + ((A.g >> 3) << 5) + (A.b >> 3);
          return *this;
          }

            ооо! biggrin.gif спасибо. это похоже должно сработать.
            1 пользователей читают эту тему (1 гостей и 0 скрытых пользователей)
            0 пользователей:


            Рейтинг@Mail.ru
            [ Script execution time: 0,0536 ]   [ 15 queries used ]   [ Generated: 19.07.25, 03:03 GMT ]