1. C++ / Говнокод #23074

    +2

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    #include <iostream>
    #include <Windows.h>
    
    #define OCT_1 0
    #define OCT_2 12
    #define OCT_3 24
    #define OCT_4 36
    #define OCT_5 48
    #define OCT_6 60
    #define OCT_7 72
    #define OCT_8 84
    #define OCT_9 96
    
    #define NOTE_C 0
    #define NOTE_Ch 1
    #define NOTE_Db 1
    #define NOTE_D 2
    #define NOTE_Dh 3
    #define NOTE_Eb 3
    #define NOTE_E 4
    #define NOTE_F 5
    #define NOTE_Fh 6
    #define NOTE_Gb 6
    #define NOTE_G 7
    #define NOTE_Gh 8
    #define NOTE_Ab 8
    #define NOTE_A 9
    #define NOTE_Ah 10
    #define NOTE_Bb 10
    #define NOTE_B 11
    
    long double notes[200];
    
    #define TEMPO 100
    #define LEN1 (120000 / TEMPO)
    #define LEN2 (LEN1 / 2)
    #define LEN4 (LEN1 / 4)
    #define LEN8 (LEN1 / 8)
    #define LEN16 (LEN1 / 16)
    
    #define melody_len 28
    struct s {
    	int key, len;
    	s(int key, int len) {
    		this->key = key;
    		this->len = len;
    	}
    } melody[melody_len] = {
    	s(OCT_4 + NOTE_E, LEN8),
    	s(OCT_4 + NOTE_E, LEN8),
    	s(OCT_5 + NOTE_C, LEN4),
    	
    	s(OCT_4 + NOTE_E, LEN8),
    	s(OCT_4 + NOTE_E, LEN8),
    	s(OCT_5 + NOTE_C, LEN4),
    	
    	s(OCT_5 + NOTE_C, LEN8),
    	s(OCT_5 + NOTE_C, LEN8),
    	s(OCT_4 + NOTE_B, LEN8),
    	s(OCT_4 + NOTE_B, LEN8),
    	
    	s(OCT_5 + NOTE_C, LEN8),
    	s(OCT_5 + NOTE_C, LEN8),
    	s(OCT_4 + NOTE_E, LEN4),
    	
    	s(OCT_5 + NOTE_E, LEN8),
    	s(OCT_5 + NOTE_E, LEN8),
    	s(OCT_4 + NOTE_D, LEN8),
    	s(OCT_4 + NOTE_D, LEN8),
    	
    	s(OCT_5 + NOTE_E, LEN8),
    	s(OCT_5 + NOTE_E, LEN8),
    	s(OCT_4 + NOTE_B, LEN8),
    	s(OCT_4 + NOTE_B, LEN8),
    	
    	s(OCT_5 + NOTE_C, LEN8),
    	s(OCT_5 + NOTE_C, LEN8),
    	s(OCT_4 + NOTE_B, LEN8),
    	s(OCT_4 + NOTE_B, LEN8),
    	
    	s(OCT_5 + NOTE_C, LEN8),
    	s(OCT_5 + NOTE_C, LEN8),
    	s(OCT_4 + NOTE_E, LEN4),
    };
    
    int main(int argc, char** argv) {
    	notes[0] = 32.7032;
    	for(int i = 1; i < 200; ++i)
    		notes[i] = notes[i - 1] * 1.05946309436;
    		
    	for(int i = 0; i < melody_len; ++i) {
    		int key = melody[i].key;
    		int len = melody[i].len;
    		
    		if(key < 0) Sleep(len);
    		else Beep(notes[key], len);
    	}
    	
    	return 0;
    }

    Дохуя мелодия... с 1 класса музыкалки...

    Losyash1337, 27 Мая 2017

    Комментарии (8)
  2. C++ / Говнокод #23072

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    for (int i = 0; i < WorkedVerts.count(); i++)
    	{
    		int R0 = (i + Offset0) % WorkedVerts.count();
    		int R1 = (i + Offset1) % WorkedVerts.count();
    		int R2 = (i + Offset2) % WorkedVerts.count();
    
    		XA << WorkedVerts.at(R0).Position;
    		XB << WorkedVerts.at(R1).Position;
    		XC << WorkedVerts.at(R2).Position;
    	}
    	PrepareDataPointers(XA, XB, XC);
    	Inset_Cuda(InputData0, InputData1, InputData2, OutputData, XA.count(), -Amount);
    
    	for (int x = 0; x < XA.count(); x++)
    	{
    		if (fabs(OutputData[x].x) < 0.0001f && fabs(OutputData[x].y) < 0.0001f && fabs(OutputData[x].z < 0.0001f))
    		{
    			int Start = x;
    			int Start1 = (x + (XA.count() - 1)) % XA.count();
    			QVector3D StartVec = QVector3D(OutputData[Start1].x, OutputData[Start1].y, OutputData[Start1].z);
    			QVector3D EndVec = StartVec;
    			int End = 0;
    			while (true)
    			{
    				End = Start++;
    				if (fabs(OutputData[End].x) > 0.0001f && fabs(OutputData[End].y) > 0.0001f && fabs(OutputData[End].z > 0.0001f))
    				{
    					EndVec = QVector3D(OutputData[End].x, OutputData[End].y, OutputData[End].z);
    					break;
    				}
    			}
    			QVector3D OffsetX0 = WorkedVerts.at(Start).Position - StartVec;
    			QVector3D OffsetX1 = WorkedVerts.at(End).Position - EndVec;
    			QVector3D Mid2 = OffsetX0 + (OffsetX1 - OffsetX0) * 0.5f;
    			OutputData[x].x = Mid2.x();
    			OutputData[x].y = Mid2.y();
    			OutputData[x].z = Mid2.z();
    		}
    	}
    	int VertsCounter = SharedVerts.count();
    	for (int i = 0; i < WorkedVerts.count(); i++)
    	{
    		SharedVertex NewVert;
    		int Count3 = WorkedVerts.count();
    		int index = (i + (Count3 - 1)) % Count3;
    		NewVert.Position = QVector3D(OutputData[index].x, OutputData[index].y, OutputData[index].z);
    		NewVert.Index = VertsCounter++;
    		SV2 << NewVert;
    	}

    Код нахождения копии контура вершин с оффсетом.

    IVK, 26 Мая 2017

    Комментарии (3)
  3. C++ / Говнокод #23066

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    #include <bits/stdc++.h> 
            
    using namespace std;
              
    int B[105], N, k, u, v, i, z;
    map<int, int> A;
            
    main()
    {
        for(cin >> N; cin >> k; B[i++] = k)
            ++A[k] > v ? v = A[u = k] :
                A[k] ^ v ?: u = min(u, k);
               
        for(; z < N; z++)
            B[z] == u || cout << B[z] << " ";
                                         
        while(v--) cout << u << " ";
    }

    Решение задачи из acmp, первое место по количеству символов, обогнав других участников на 30 и более символов.

    Обычное решение задачи, тех которые не участвовали у конке, количество символов от 600-700 символов, тут же 208 символов

    aat, 24 Мая 2017

    Комментарии (126)
  4. C++ / Говнокод #23064

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    template<typename T> FORCEINLINE typename std::enable_if<Is_CastToFloat<T>::value, UFloatStat*>::
      type Add(T &v ,const FStatInfo &Info=FStatInfo::Empty, bool Visible=true)
      {
        float vf=(float)v;
        auto r=_AddFloat(vf, Info, Visible);
        T vb=static_cast<T>(vf);
        if(vb!=v)
          v=vb;//const_cast<T&>(v)=vb;
        return r;
      }

    // Method for Enum, Integer types and bool

    antondoe, 24 Мая 2017

    Комментарии (0)
  5. C++ / Говнокод #23026

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    #include "hex.h"
    #include "aes.h"
    #include <stdio.h>
    
    #define KEY (0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c)
    #define DATA (0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34)
    
    unsigned char enc[] = { BPP_AES_ENCRYPT_ARRAY(KEY, DATA) };
    
    int main() {
        for (int i=0; i<sizeof(enc); ++i) {
            printf("%02X ", enc[i]);
        }
        printf("\n");
        return 0;

    HAPKOMAH, 14 Мая 2017

    Комментарии (8)
  6. C++ / Говнокод #23013

    −17

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    #include <iostream>
    
    template <unsigned long destiny>
    struct dice {
        static const unsigned long roll = destiny * 1103515245 + 12345;
    };
    
    struct happiness {};
    
    template <typename XX, typename XY>
    struct love {
        typedef XX HACTEHbKA;
        typedef XY bormand;
    };
    
    template <int magic>
    struct bormand {
        static const unsigned long destiny = magic;
    };
    
    typedef
        love<bormand<196>, love<bormand<136>, love<bormand<230>,
        love<bormand< 80>, love<bormand< 83>, love<bormand<237>,
        love<bormand<100>, love<bormand< 51>, love<bormand< 19>,
        love<bormand<166>, love<bormand< 12>, love<bormand<153>,
        love<bormand<229>, love<bormand<141>, love<bormand<125>,
        happiness          >>>>>>>>>>>>>>>    HACTEHbKA;
    
    template<typename LOVE, unsigned long destiny>
    struct mystery {
        typedef
            love<bormand<LOVE::HACTEHbKA::destiny ^ dice<destiny>::roll>,
            typename mystery<typename LOVE::bormand,
            dice<destiny>::roll>::unveiled> unveiled;
    };
    
    template<unsigned long destiny>
    struct mystery<happiness, destiny> {
        typedef happiness unveiled;
    };
    
    template<typename love>
    std::string dreams_come_true(const love&) {
        return std::string(1, love::HACTEHbKA::destiny) +
               dreams_come_true(typename love::bormand());
    }
    
    std::string dreams_come_true(const happiness&) {
        return std::string();
    }
    
    int main() {
        std::cout << dreams_come_true(mystery<HACTEHbKA, 1>::unveiled());
    }

    Я перепесала http://govnokod.ru/21198 через вычесления на чистом уровне и кампеляции как моя чистая любовь

    guestinh0, 11 Мая 2017

    Комментарии (21)
  7. C++ / Говнокод #23012

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    void __attribute__ ((naked)) c8_handler_i() {
        asm volatile (
            "push %%ebp             \n\
            mov %%esp, %%ebp        \n\
            sub $20, %%esp          \n\
            mov %%eax, -4(%%ebp)    \n\
            mov %%ebx, -8(%%ebp)    \n\
            mov %%edx, -12(%%ebp)   \n\
            mov %[tasks], %%ebx     \n\
            mov %[cur_task], %%eax  \n\
            mov %[t_sz], %%edx      \n\
            mov (%%eax), %%eax      \n\
            mul %%edx               \n\
            add %%eax, %%ebx        \n\
            mov -4(%%ebp), %%eax    \n\
            mov %%eax, (%%ebx)      \n\
            mov -8(%%ebp), %%eax    \n\
            mov %%eax, 4(%%ebx)     \n\
            mov %%ecx, 8(%%ebx)     \n\
            mov -12(%%ebp), %%eax   \n\
            mov %%eax, 12(%%ebx)    \n\
            mov %%esi, 16(%%ebx)    \n\
            mov %%edi, 20(%%ebx)    \n\
            mov %%ebp, 24(%%ebx)    \n\
            addl $4, 24(%%ebx)      \n\
            mov (%%ebp), %%eax      \n\
            mov %%eax, 28(%%ebx)    \n\
            mov -4(%%ebp), %%eax    \n\
            mov -8(%%ebp), %%ebx    \n\
            mov -12(%%ebp), %%edx   \n\
            add $20, %%esp          \n\
            pop %%ebp               \n\
            iret"
            :: [tasks] "i" (tasks), [cur_task] "i" (&cur_task),
               [t_sz] "i" (sizeof(task)), [t_eip] "i" (offsetof(task, eip)), 
               [t_ebx] "i" (offsetof(reg_values, ebx))
        );
    }

    Когда решился написать ОС на C++

    cykablyad, 11 Мая 2017

    Комментарии (32)
  8. C++ / Говнокод #21126

    −79

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    int main( void )
    {
        fraction f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15;
        fraction t1f1, t1f2, t1f3, t1f4, t1f5, t1f6, t1f7, t1f8, t1f9, t1f10, t1f11, t1f12, t1f13, t1f14, t1f15;
        fraction t2f1, t2f2, t2f3, t2f4, t2f5, t2f6, t2f7, t2f8, t2f9, t2f10, t2f11, t2f12, t2f13, t2f14, t2f15;
        fraction t3f1, t3f2, t3f3, t3f4, t3f5, t3f6, t3f7, t3f8, t3f9, t3f10, t3f11, t3f12, t3f13, t3f14, t3f15;
        fraction t4f1, t4f2, t4f3, t4f4, t4f5, t4f6, t4f7, t4f8, t4f9, t4f10, t4f11, t4f12, t4f13, t4f14, t4f15;
        fraction t5f1, t5f2, t5f3, t5f4, t5f5, t5f6, t5f7, t5f8, t5f9, t5f10, t5f11, t5f12, t5f13, t5f14, t5f15;
        fraction t6f1, t6f2, t6f3, t6f4, t6f5, t6f6, t6f7, t6f8, t6f9, t6f10, t6f11, t6f12, t6f13, t6f14, t6f15;
        fraction t7f1, t7f2, t7f3, t7f4, t7f5, t7f6, t7f7, t7f8, t7f9, t7f10, t7f11, t7f12, t7f13, t7f14, t7f15;
        fraction t8f1, t8f2, t8f3, t8f4, t8f5, t8f6, t8f7, t8f8, t8f9, t8f10, t8f11, t8f12, t8f13, t8f14, t8f15;
        fraction t9f1, t9f2, t9f3, t9f4, t9f5, t9f6, t9f7, t9f8, t9f9, t9f10, t9f11, t9f12, t9f13, t9f14, t9f15;
        fraction t10f1, t10f2, t10f3, t10f4, t10f5, t10f6, t10f7, t10f8, t10f9, t10f10, t10f11, t10f12, t10f13, t10f14, t10f15;
        fraction t11f1, t11f2, t11f3, t11f4, t11f5, t11f6, t11f7, t11f8, t11f9, t11f10, t11f11, t11f12, t11f13, t11f14, t11f15;
        fraction t12f1, t12f2, t12f3, t12f4, t12f5, t12f6, t12f7, t12f8, t12f9, t12f10, t12f11, t12f12, t12f13, t12f14, t12f15;
        fraction t13f1, t13f2, t13f3, t13f4, t13f5, t13f6, t13f7, t13f8, t13f9, t13f10, t13f11, t13f12, t13f13, t13f14, t13f15;
        fraction t14f1, t14f2, t14f3, t14f4, t14f5, t14f6, t14f7, t14f8, t14f9, t14f10, t14f11, t14f12, t14f13, t14f14, t14f15;
        fraction t15f1, t15f2, t15f3, t15f4, t15f5, t15f6, t15f7, t15f8, t15f9, t15f10, t15f11, t15f12, t15f13, t15f14, t15f15;
        fraction current;
        current.getnum( 1 );
        int den( 0 );
        int num ( 1 );
        do
        {
            cout << "Enter den: ";
            cin >> den;
            if( den > 16 )
            {
                cout << "Very big den! Try again!" << endl;
                continue;
            }
            if( den < 2 )
            {
                cout << "Very small den! Try again!" << endl;
                continue;
            }
            current.getden( den );
        }
        while( den > 16 || den < 2 );
    //////////////////////////////////////////////////////////////////////////////////////////////
        cout << endl;
        cout << "----------------------------------------------------------------------" << endl;
        f1 = current;
        f1.showfrac( ); cout << " ";
        current.getnum( ++num );
        if( den > num )
        {
            f2 = current;
            f2.lowterms( );
            f2.showfrac( ); cout << " ";
        }
        current.getnum( ++num );
        if( den > num )
        {
            f3 = current;
            f3.lowterms( );
            f3.showfrac( ); cout << " ";
        }
        current.getnum( ++num );
        if( den > num )
        {
            f4 = current;
            f4.lowterms( );
            f4.showfrac( ); cout << " ";
        }
        current.getnum( ++num );
        if( den > num )
        {
            f5 = current;
            f5.lowterms( );
            f5.showfrac( ); cout << " ";
        }
        current.getnum( ++num );
        if( den > num )
        {
            f6 = current;
            f6.lowterms( );
            f6.showfrac( ); cout << " ";
        }
        current.getnum( ++num );
        if( den > num )
        {
            f7 = current;
            f7.lowterms( );
            f7.showfrac( ); cout << " ";
        }
        current.getnum( ++num );
        if( den > num )
        {
            f8 = current;
            f8.lowterms( );
            f8.showfrac( ); cout << " ";
        }
        current.getnum( ++num );
        if( den > num )
        {
            f9 = current;

    Выполнение задания. Массивы? Проверка ввода? Не, не слышали!

    BaronDeLotion, 07 Сентября 2016

    Комментарии (15)
  9. C++ / Говнокод #21125

    +26

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    for(devIndex=0;SetupDiEnumDeviceInfo(devs,devIndex,&devInfo);devIndex++) {
    
            if(doSearch) {
                for(argIndex=skip,match=FALSE;(argIndex<argc) && !match;argIndex++) {
                    TCHAR devID[MAX_DEVICE_ID_LEN];
                    LPTSTR *hwIds = NULL;
                    LPTSTR *compatIds = NULL;
                    //
                    // determine instance ID
                    //
                    if(CM_Get_Device_ID_Ex(devInfo.DevInst,devID,MAX_DEVICE_ID_LEN,0,devInfoListDetail.RemoteMachineHandle)!=CR_SUCCESS) {
                        devID[0] = TEXT('\0');
                    }
    ...
    }

    Лучший стиль форматирования кода от индусов из MS.
    Код взят из этого файла:
    https://github.com/Microsoft/Windows-driver-samples/blob/master/setup/devcon/devcon.cpp
    В других файлах код примерно аналогичный.

    demoth, 07 Сентября 2016

    Комментарии (13)
  10. C++ / Говнокод #21054

    +410

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    CBroadcastPropPP::CBroadcastPropPP()
    {
    m_bAdminMode = FALSE;
    
    m_aProps.Add(new CRPProp_01);
    m_aProps.Add(new CRPProp_02);
    m_aProps.Add(new CRPProp_021);
    m_aProps.Add(new CRPProp_022);
    m_aProps.Add(new CRPProp_03);
    m_aProps.Add(new CRPProp_05);
    m_aProps.Add(new CRPProp_06);
    m_aProps.Add(new CRPProp_07);
    }
    
    #define PPPos_Dir 0
    #define PPPos_Recursive 1
    #define PPPos_Masks 2
    #define PPPos_MaxSize 3
    #define PPPos_Archive 4
    #define PPPos_Subject 5
    #define PPPos_Types 6
    #define PPPos_MaxRcpt 7
    #define PPPos_BCC 8
    
    void CBroadcastPropPP::Initialize(IRegistrato​r* pRegistrator)
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState(​ ));
     m_pRegistrator=pRegistrator;
    
    ((CRPProp_01*)(m_aProps[PPPos_Dir]))->_I​nitialize(m_pRegistrator->m_sStartupPath,​ m_pRegistrator);
    ((CRPProp_02*)(m_aProps[PPPos_Recursive]​))->_Initialize(m_pRegistrator->m_sStart​upPath, m_pRegistrator);
    ((CRPProp_021*)(m_aProps[PPPos_Masks]))-​>_Initialize(m_pRegistrator->m_sStartupP​ath, m_pRegistrator);
    ((CRPProp_022*)(m_aProps[PPPos_MaxSize])​)->_Initialize(m_pRegistrator->m_sStartu​pPath, m_pRegistrator);
    ((CRPProp_03*)(m_aProps[PPPos_Archive]))​->_Initialize(m_pRegistrator->m_sStartup​Path, m_pRegistrator);
    ((CRPProp_05*)(m_aProps[PPPos_Types]))->_​Initialize(&m_pRegistrator->m_DB,m_pRegistrator->m_s​StartupPath);
    ((CRPProp_06*)(m_aProps[PPPos_MaxRcpt]))​->_Initialize(m_pRegistrator->m_sStartup​Path, m_pRegistrator );
    ((CRPProp_07*)(m_aProps[PPPos_BCC]))->_I​nitialize(m_pRegistrator->m_sStartupPath,​ m_pRegistrator );
    }
    
    CBroadcastPropPP::~CBroadcastPropPP()
    {
    delete (CRPProp_01*)m_aProps[PPPos_Dir];
    delete (CRPProp_02*)m_aProps[PPPos_Recursive];
    delete (CRPProp_021*)m_aProps[PPPos_Masks];
    delete (CRPProp_022*)m_aProps[PPPos_MaxSize];
    delete (CRPProp_03*)m_aProps[PPPos_Archive];
    delete (CRPProp_05*)m_aProps[PPPos_Types];
    delete (CRPProp_06*)m_aProps[PPPos_MaxRcpt];
    delete (CRPProp_07*)m_aProps[PPPos_BCC];
    }

    «Вот что бывает, когда пишешь на C++, не зная, зачем нужны виртуальные деструкторы...

    классы CRPProp_0n - производные от общего базового класса. Вроде задумка неплохая, можно работать с их массивом, удобно. Но видимо, что-то не заладилось, почему-то их методы не вызывались (про виртуальные функции разработчик не знал)... И тут на выручку эмо-кодеру пришло приведение типов! Правда, про работу с массивом в цикле пришлось забыть...»


    Источник: http://emo-coders.livejournal.com/59977.html

    inkanus-gray, 01 Сентября 2016

    Комментарии (20)