0 / 0 / 0
Регистрация: 29.08.2020
Сообщений: 23
1

Создание массива объектов шаблонного класса С++

27.05.2021, 16:07. Показов 5698. Ответов 1
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Всем привет. В ходе выполнения работы столкнулся с потребностью в создании динамического массива объектов шаблонного класса. Но вот беда, создать через array<TempArray^>^ arr = gcnew array<TempArray^>(10) не получается.
Подскажите еще какой-либо метод написания массива объектов шаблонного класса пожалуйта.

Код формы
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
#pragma once
 
#include"TempArray.h"
#include<vector>
 
namespace OOP7_4 {
 
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
 
    /// <summary>
    /// Сводка для Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: добавьте код конструктора
            //
        }
 
    protected:
        /// <summary>
        /// Освободить все используемые ресурсы.
        /// </summary>
        ~Form1()
        {
    // 
            
            // lbCi
            // 
            this->lbCi->AutoSize = true;
            this->lbCi->Location = System::Drawing::Point(6, 229);
            this->lbCi->Name = L"lbCi";
            this->lbCi->Size = System::Drawing::Size(164, 17);
            this->lbCi->TabIndex = 2;
            this->lbCi->Text = L"Количество элементов:";
            // 
            // dgvInt
            // 
            this->dgvInt->AllowUserToAddRows = false;
            this->dgvInt->AutoSizeColumnsMode = System::Windows::Forms::DataGridViewAutoSizeColumnsMode::AllCells;
            this->dgvInt->AutoSizeRowsMode = System::Windows::Forms::DataGridViewAutoSizeRowsMode::AllCells;
            this->dgvInt->BackgroundColor = System::Drawing::SystemColors::Control;
            this->dgvInt->CellBorderStyle = System::Windows::Forms::DataGridViewCellBorderStyle::Raised;
            this->dgvInt->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
            this->dgvInt->ColumnHeadersVisible = false;
            this->dgvInt->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^  >(3) {this->dataGridViewTextBoxColumn1, 
                this->dataGridViewTextBoxColumn2, this->dataGridViewTextBoxColumn3});
            this->dgvInt->GridColor = System::Drawing::SystemColors::Control;
            this->dgvInt->Location = System::Drawing::Point(6, 6);
            this->dgvInt->Name = L"dgvInt";
            this->dgvInt->RowHeadersVisible = false;
            this->dgvInt->RowTemplate->Height = 24;
            this->dgvInt->Size = System::Drawing::Size(457, 211);
            this->dgvInt->TabIndex = 1;
            this->dgvInt->CellEndEdit += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &Form1::dgvInt_CellEndEdit);
            // 
            // dataGridViewTextBoxColumn1
            // 
            this->dataGridViewTextBoxColumn1->Name = L"dataGridViewTextBoxColumn1";
            this->dataGridViewTextBoxColumn1->Width = 5;
            // 
            // dataGridViewTextBoxColumn2
            // 
            this->dataGridViewTextBoxColumn2->Name = L"dataGridViewTextBoxColumn2";
            this->dataGridViewTextBoxColumn2->Width = 5;
            // 
            // dataGridViewTextBoxColumn3
            // 
            this->dataGridViewTextBoxColumn3->Name = L"dataGridViewTextBoxColumn3";
            this->dataGridViewTextBoxColumn3->Width = 5;
            // 
            // btnClear1
            // 
            this->btnClear1->Location = System::Drawing::Point(799, 308);
            this->btnClear1->Name = L"btnClear1";
            this->btnClear1->Size = System::Drawing::Size(102, 34);
            this->btnClear1->TabIndex = 0;
            this->btnClear1->Text = L"Очистить";
            this->btnClear1->UseVisualStyleBackColor = true;
            // 
            // tabPage2
            // 
            this->tabPage2->BackColor = System::Drawing::SystemColors::Control;
            this->tabPage2->Controls->Add(this->button5);
            this->tabPage2->Controls->Add(this->button1);
            this->tabPage2->Controls->Add(this->button6);
            this->tabPage2->Controls->Add(this->label4);
            this->tabPage2->Controls->Add(this->dgvDouble);
            this->tabPage2->Controls->Add(this->button2);
            this->tabPage2->Controls->Add(this->btnClear2);
            this->tabPage2->Controls->Add(this->label1);
            this->tabPage2->Location = System::Drawing::Point(4, 25);
            this->tabPage2->Name = L"tabPage2";
            this->tabPage2->Padding = System::Windows::Forms::Padding(3);
            this->tabPage2->Size = System::Drawing::Size(907, 348);
            this->tabPage2->TabIndex = 1;
            this->tabPage2->Text = L"Вещественные";
            // 
            // button5
            // 
            this->button5->Location = System::Drawing::Point(469, 61);
            this->button5->Name = L"button5";
            this->button5->Size = System::Drawing::Size(41, 29);
            this->button5->TabIndex = 10;
            this->button5->Text = L"-";
            this->button5->UseVisualStyleBackColor = true;
            this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click_1);
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(169, 223);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(41, 29);
            this->button1->TabIndex = 7;
            this->button1->Text = L"-";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            // 
            // button6
            // 
            this->button6->Location = System::Drawing::Point(469, 26);
            this->button6->Name = L"button6";
            this->button6->Size = System::Drawing::Size(41, 29);
            this->button6->TabIndex = 9;
            this->button6->Text = L"+";
            this->button6->UseVisualStyleBackColor = true;
            this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click_1);
            // 
            // label4
            // 
            this->label4->AutoSize = true;
            this->label4->Location = System::Drawing::Point(466, 6);
            this->label4->Name = L"label4";
            this->label4->Size = System::Drawing::Size(155, 17);
            this->label4->TabIndex = 8;
            this->label4->Text = L"Количество массивов:";
            // 
            // dgvDouble
            // 
            this->dgvDouble->AllowUserToAddRows = false;
            this->dgvDouble->AutoSizeColumnsMode = System::Windows::Forms::DataGridViewAutoSizeColumnsMode::AllCells;
            this->dgvDouble->AutoSizeRowsMode = System::Windows::Forms::DataGridViewAutoSizeRowsMode::AllCells;
            this->dgvDouble->BackgroundColor = System::Drawing::SystemColors::Control;
            this->dgvDouble->CellBorderStyle = System::Windows::Forms::DataGridViewCellBorderStyle::Raised;
            this->dgvDouble->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
            this->dgvDouble->ColumnHeadersVisible = false;
            this->dgvDouble->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^  >(3) {this->dataGridViewTextBoxColumn7, 
                this->dataGridViewTextBoxColumn8, this->dataGridViewTextBoxColumn9});
            this->dgvDouble->GridColor = System::Drawing::SystemColors::Control;
            this->dgvDouble->Location = System::Drawing::Point(6, 6);
            this->dgvDouble->Name = L"dgvDouble";
            this->dgvDouble->RowHeadersVisible = false;
            this->dgvDouble->RowTemplate->Height = 24;
            this->dgvDouble->Size = System::Drawing::Size(457, 211);
            this->dgvDouble->TabIndex = 4;
            this->dgvDouble->CellEndEdit += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &Form1::dgvDouble_CellEndEdit);
            // 
            // dataGridViewTextBoxColumn7
            // 
            this->dataGridViewTextBoxColumn7->Name = L"dataGridViewTextBoxColumn7";
            this->dataGridViewTextBoxColumn7->Width = 5;
            // 
            // dataGridViewTextBoxColumn8
            // 
            this->dataGridViewTextBoxColumn8->Name = L"dataGridViewTextBoxColumn8";
            this->dataGridViewTextBoxColumn8->Width = 5;
            // 
            // dataGridViewTextBoxColumn9
            // 
            this->dataGridViewTextBoxColumn9->Name = L"dataGridViewTextBoxColumn9";
            this->dataGridViewTextBoxColumn9->Width = 5;
            // 
            // button2
            // 
            this->button2->Location = System::Drawing::Point(216, 223);
            this->button2->Name = L"button2";
            this->button2->Size = System::Drawing::Size(41, 29);
            this->button2->TabIndex = 6;
            this->button2->Text = L"+";
            this->button2->UseVisualStyleBackColor = true;
            this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
            // 
            // btnClear2
            // 
            this->btnClear2->Location = System::Drawing::Point(799, 308);
            this->btnClear2->Name = L"btnClear2";
            this->btnClear2->Size = System::Drawing::Size(102, 34);
            this->btnClear2->TabIndex = 0;
            this->btnClear2->Text = L"Очистить";
            this->btnClear2->UseVisualStyleBackColor = true;
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(6, 229);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(164, 17);
            this->label1->TabIndex = 5;
            this->label1->Text = L"Количество элементов:";
            // 
            // tabPage3
            // 
            this->tabPage3->BackColor = System::Drawing::SystemColors::Control;
            this->tabPage3->Controls->Add(this->button7);
            this->tabPage3->Controls->Add(this->button3);
            this->tabPage3->Controls->Add(this->button8);
            this->tabPage3->Controls->Add(this->dgvCh);
            this->tabPage3->Controls->Add(this->label5);
            this->tabPage3->Controls->Add(this->button4);
            this->tabPage3->Controls->Add(this->btnClear3);
            this->tabPage3->Controls->Add(this->label2);
            this->tabPage3->Location = System::Drawing::Point(4, 25);
            this->tabPage3->Name = L"tabPage3";
            this->tabPage3->Padding = System::Windows::Forms::Padding(3);
            this->tabPage3->Size = System::Drawing::Size(907, 348);
            this->tabPage3->TabIndex = 2;
            this->tabPage3->Text = L"Символьные";
            // 
            // button7
            // 
            this->button7->Location = System::Drawing::Point(472, 61);
            this->button7->Name = L"button7";
            this->button7->Size = System::Drawing::Size(41, 29);
            this->button7->TabIndex = 13;
            this->button7->Text = L"-";
            this->button7->UseVisualStyleBackColor = true;
            this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
            // 
            // button3
            // 
            this->button3->Location = System::Drawing::Point(169, 223);
            this->button3->Name = L"button3";
            this->button3->Size = System::Drawing::Size(41, 29);
            this->button3->TabIndex = 7;
            this->button3->Text = L"-";
            this->button3->UseVisualStyleBackColor = true;
            this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
            // 
            // button8
            // 
            this->button8->Location = System::Drawing::Point(472, 26);
            this->button8->Name = L"button8";
            this->button8->Size = System::Drawing::Size(41, 29);
            this->button8->TabIndex = 12;
            this->button8->Text = L"+";
            this->button8->UseVisualStyleBackColor = true;
            this->button8->Click += gcnew System::EventHandler(this, &Form1::button8_Click);
            // 
            // dgvCh
            // 
            this->dgvCh->AllowUserToAddRows = false;
            this->dgvCh->AutoSizeColumnsMode = System::Windows::Forms::DataGridViewAutoSizeColumnsMode::AllCells;
            this->dgvCh->AutoSizeRowsMode = System::Windows::Forms::DataGridViewAutoSizeRowsMode::AllCells;
            this->dgvCh->BackgroundColor = System::Drawing::SystemColors::Control;
            this->dgvCh->CellBorderStyle = System::Windows::Forms::DataGridViewCellBorderStyle::Raised;
            this->dgvCh->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
            this->dgvCh->ColumnHeadersVisible = false;
            this->dgvCh->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^  >(3) {this->dataGridViewTextBoxColumn4, 
                this->dataGridViewTextBoxColumn5, this->dataGridViewTextBoxColumn6});
            this->dgvCh->GridColor = System::Drawing::SystemColors::Control;
            this->dgvCh->Location = System::Drawing::Point(6, 6);
            this->dgvCh->Name = L"dgvCh";
            this->dgvCh->RowHeadersVisible = false;
            this->dgvCh->RowTemplate->Height = 24;
            this->dgvCh->Size = System::Drawing::Size(457, 211);
            this->dgvCh->TabIndex = 3;
            // 
            // dataGridViewTextBoxColumn4
            // 
            this->dataGridViewTextBoxColumn4->Name = L"dataGridViewTextBoxColumn4";
            this->dataGridViewTextBoxColumn4->Width = 5;
            // 
            // dataGridViewTextBoxColumn5
            // 
            this->dataGridViewTextBoxColumn5->Name = L"dataGridViewTextBoxColumn5";
            this->dataGridViewTextBoxColumn5->Width = 5;
            // 
            // dataGridViewTextBoxColumn6
            // 
            this->dataGridViewTextBoxColumn6->Name = L"dataGridViewTextBoxColumn6";
            this->dataGridViewTextBoxColumn6->Width = 5;
            // 
            // label5
            // 
            this->label5->AutoSize = true;
            this->label5->Location = System::Drawing::Point(469, 6);
            this->label5->Name = L"label5";
            this->label5->Size = System::Drawing::Size(155, 17);
            this->label5->TabIndex = 11;
            this->label5->Text = L"Количество массивов:";
            // 
            // button4
            // 
            this->button4->Location = System::Drawing::Point(216, 223);
            this->button4->Name = L"button4";
            this->button4->Size = System::Drawing::Size(41, 29);
            this->button4->TabIndex = 6;
            this->button4->Text = L"+";
            this->button4->UseVisualStyleBackColor = true;
            this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
            // 
            // btnClear3
            // 
            this->btnClear3->Location = System::Drawing::Point(799, 308);
            this->btnClear3->Name = L"btnClear3";
            this->btnClear3->Size = System::Drawing::Size(102, 34);
            this->btnClear3->TabIndex = 0;
            this->btnClear3->Text = L"Очистить";
            this->btnClear3->UseVisualStyleBackColor = true;
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(6, 229);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(164, 17);
            this->label2->TabIndex = 5;
            this->label2->Text = L"Количество элементов:";
            // 
            // btnExit
            // 
            this->btnExit->Location = System::Drawing::Point(815, 395);
            this->btnExit->Name = L"btnExit";
            this->btnExit->Size = System::Drawing::Size(102, 33);
            this->btnExit->TabIndex = 1;
            this->btnExit->Text = L"Выход";
            this->btnExit->UseVisualStyleBackColor = true;
            this->btnExit->Click += gcnew System::EventHandler(this, &Form1::btnExit_Click);
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(939, 440);
            this->Controls->Add(this->btnExit);
            this->Controls->Add(this->tabControl1);
            this->Name = L"Form1";
            this->Text = L"Шаблон массивов";
            this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
            this->tabControl1->ResumeLayout(false);
            this->tabPage1->ResumeLayout(false);
            this->tabPage1->PerformLayout();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dgvInt))->EndInit();
            this->tabPage2->ResumeLayout(false);
            this->tabPage2->PerformLayout();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dgvDouble))->EndInit();
            this->tabPage3->ResumeLayout(false);
            this->tabPage3->PerformLayout();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dgvCh))->EndInit();
            this->ResumeLayout(false);
 
        }
#pragma endregion
        //Обработчик события загрузки формы приложения
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
                 //Инициализация и обработка таблицы значений с вкладки "Целые"
                 dgvInt->RowCount = 3;
                 dgvInt->ColumnCount = 3;
                 dgvInt->Rows[0]->Cells[0]->Value = "№ Массива\\элемента";
                 dgvInt->Rows[0]->Cells[0]->ReadOnly = true;
                 for(int i = 1; i < dgvInt->RowCount;i++)
                 {
                     dgvInt->Rows[i]->Cells[0]->Value = i;
                     dgvInt->Rows[i]->Cells[0]->ReadOnly = true;
 
                 }
                 for(int i = 1; i < dgvInt->ColumnCount;i++)
                 {
                     dgvInt->Rows[0]->Cells[i]->Value = i;
                     dgvInt->Rows[0]->Cells[i]->ReadOnly = true;                    
                 }
                 //Инициализация и обработка таблицы с вкладки "Вещественные"
                 dgvDouble->RowCount = 3;
                 dgvDouble->ColumnCount = 3;
                 dgvDouble->Rows[0]->Cells[0]->Value = "№ Массива\\элемента";
                 dgvDouble->Rows[0]->Cells[0]->ReadOnly = true;
                  for(int i = 1; i < dgvDouble->RowCount;i++)
                 {
                     dgvDouble->Rows[i]->Cells[0]->Value = i;
                     dgvDouble->Rows[i]->Cells[0]->ReadOnly = true;
 
                 }
                 for(int i = 1; i < dgvDouble->ColumnCount;i++)
                 {
                     dgvDouble->Rows[0]->Cells[i]->Value = i;
                     dgvDouble->Rows[0]->Cells[i]->ReadOnly = true;                 
                 }
 
                 //Инициализация и обработка таблицы с вкладки "Символьные"
                 dgvCh->RowCount = 3;
                 dgvCh->ColumnCount = 3;
                 dgvCh->Rows[0]->Cells[0]->Value = "№ Массива\\элемента";
                 dgvCh->Rows[0]->Cells[0]->ReadOnly = true;
                  for(int i = 1; i < dgvCh->RowCount;i++)
                 {
                     dgvCh->Rows[i]->Cells[0]->Value = i;
                     dgvCh->Rows[i]->Cells[0]->ReadOnly = true;
 
                 }
                 for(int i = 1; i < dgvCh->ColumnCount;i++)
                 {
                     dgvCh->Rows[0]->Cells[i]->Value = i;
                     dgvCh->Rows[0]->Cells[i]->ReadOnly = true;                 
                 }
 
 
             }
    private: System::Void btnExit_Click(System::Object^  sender, System::EventArgs^  e) {
                 this->Close();
             }
    
             //Обработчик события увеличения количества целочисленных элементов 
private: System::Void btnPi_Click(System::Object^  sender, System::EventArgs^  e) {
             dgvInt->ColumnCount += 1; 
              for(int i = 1; i < dgvInt->ColumnCount;i++)
                 {
                     dgvInt->Rows[0]->Cells[i]->Value = i;
                     dgvInt->Rows[0]->Cells[i]->ReadOnly = true;                    
                 }
         }
 
            //Обработчик события уменьшения количества целочисленных элементов 
private: System::Void btnMi_Click(System::Object^  sender, System::EventArgs^  e) {
             dgvInt->ColumnCount -= 1;
 
             if(dgvInt->ColumnCount <2)
             {
                MessageBox::Show("Массив не может быть пустым!");
                dgvInt->ColumnCount = 2;
             }
              for(int i = 1; i < dgvInt->ColumnCount;i++)
                 {
                     dgvInt->Rows[0]->Cells[i]->Value = i;
                     dgvInt->Rows[0]->Cells[i]->ReadOnly = true;                    
                 }
         }
 
         //Обработчик события увеличения количества массивов целочисленного типа
private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
             dgvInt->RowCount += 1;
             for(int i = 1; i < dgvInt->RowCount;i++)
                 {
                     dgvInt->Rows[i]->Cells[0]->Value = i;
                     dgvInt->Rows[i]->Cells[0]->ReadOnly = true;
 
                 }
         }
 
          //Обработчик события уменьшения количества массивов целочисленного типа
private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) {
             dgvInt->RowCount -= 1;
 
             if(dgvInt->RowCount<3)
             {
                MessageBox::Show("Для сравнения необхходимо минимум 2 массива!");
                dgvInt->RowCount = 3;
             }
 
             for(int i = 1; i < dgvInt->RowCount;i++)
                 {
                     dgvInt->Rows[i]->Cells[0]->Value = i;
                     dgvInt->Rows[i]->Cells[0]->ReadOnly = true;
 
                 }
         }
                  //Обработчик события увеличения количества элементов вещественного типа
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
             dgvDouble->ColumnCount += 1; 
              for(int i = 1; i < dgvDouble->ColumnCount;i++)
                 {
                     dgvDouble->Rows[0]->Cells[i]->Value = i;
                     dgvDouble->Rows[0]->Cells[i]->ReadOnly = true;                 
                 }
         }
 
                 //Обработчик события уменьшения количества элементов вещественного типа
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
              dgvDouble->ColumnCount -= 1;
 
             if(dgvDouble->ColumnCount <2)
             {
                MessageBox::Show("Массив не может быть пустым!");
                dgvDouble->ColumnCount = 2;
             }
              for(int i = 1; i < dgvDouble->ColumnCount;i++)
                 {
                     dgvDouble->Rows[0]->Cells[i]->Value = i;
                     dgvDouble->Rows[0]->Cells[i]->ReadOnly = true;                 
                 }
         }
 
         //Обработчик события Увеличения количества массивов вещественного типа
private: System::Void button6_Click_1(System::Object^  sender, System::EventArgs^  e) {
              dgvDouble->RowCount += 1;
             for(int i = 1; i < dgvDouble->RowCount;i++)
                 {
                     dgvDouble->Rows[i]->Cells[0]->Value = i;
                     dgvDouble->Rows[i]->Cells[0]->ReadOnly = true;
 
                 }
         }
 
          //Обработчик события уменьшения количества массивов вещественного типа
private: System::Void button5_Click_1(System::Object^  sender, System::EventArgs^  e) {
               dgvDouble->RowCount -= 1;
 
             if(dgvDouble->RowCount<3)
             {
                MessageBox::Show("Для сравнения необхходимо минимум 2 массива!");
                dgvDouble->RowCount = 3;
             }
 
             for(int i = 1; i < dgvDouble->RowCount;i++)
                 {
                     dgvDouble->Rows[i]->Cells[0]->Value = i;
                     dgvDouble->Rows[i]->Cells[0]->ReadOnly = true;
 
                 }
         }
 
         //Обработчик события увеличения количества элементов символьного типа
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
             dgvCh->ColumnCount += 1; 
              for(int i = 1; i < dgvCh->ColumnCount;i++)
                 {
                     dgvCh->Rows[0]->Cells[i]->Value = i;
                     dgvCh->Rows[0]->Cells[i]->ReadOnly = true;                 
                 }
         }
 
         //Обработчик события уменьшения количества элементов символьного типа
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
              dgvCh->ColumnCount -= 1;
 
             if(dgvCh->ColumnCount <2)
             {
                MessageBox::Show("Массив не может быть пустым!");
                dgvCh->ColumnCount = 2;
             }
              for(int i = 1; i < dgvCh->ColumnCount;i++)
                 {
                     dgvCh->Rows[0]->Cells[i]->Value = i;
                     dgvCh->Rows[0]->Cells[i]->ReadOnly = true;                 
                 }
         }
         //Обработчик события увеличения количества массивов символьного типа
private: System::Void button8_Click(System::Object^  sender, System::EventArgs^  e) {
               dgvCh->RowCount += 1;
             for(int i = 1; i < dgvCh->RowCount;i++)
                 {
                     dgvCh->Rows[i]->Cells[0]->Value = i;
                     dgvCh->Rows[i]->Cells[0]->ReadOnly = true;
 
                 }
         }
private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) {
 
             dgvCh->RowCount -= 1;
 
             if(dgvCh->RowCount<3)
             {
                MessageBox::Show("Для сравнения необхходимо минимум 2 массива!");
                dgvCh->RowCount = 3;
             }
 
             for(int i = 1; i < dgvCh->RowCount;i++)
                 {
                     dgvCh->Rows[i]->Cells[0]->Value = i;
                     dgvCh->Rows[i]->Cells[0]->ReadOnly = true;
                 }
         }
private: System::Void dgvDouble_CellEndEdit(System::Object^  sender, System::Windows::Forms::DataGridViewCellEventArgs^  e) {
             try
                 {
                     double^ doub;
                     doub = System::Convert::ToDouble(dgvDouble->Rows[e->RowIndex]->Cells[e->ColumnIndex]->Value);
                 }
                 catch(Exception^)
                 {
                     MessageBox::Show("Введите число вещественного типа" );
                     dgvDouble->Rows[e->RowIndex]->Cells[e->ColumnIndex]->Value = nullptr;
                 }
 
         }
private: System::Void dgvInt_CellEndEdit(System::Object^  sender, System::Windows::Forms::DataGridViewCellEventArgs^  e) {
                 try
                 {
                     int^ ints;
                     ints = System::Convert::ToInt32(dgvInt->Rows[e->RowIndex]->Cells[e->ColumnIndex]->Value);
                 }
                 catch(Exception^)
                 {
                     MessageBox::Show("Введите число целочисленного типа" );
                     dgvInt->Rows[e->RowIndex]->Cells[e->ColumnIndex]->Value = nullptr;
                 }
 
         }
private: System::Void button9_Click(System::Object^  sender, System::EventArgs^  e) {
             int rowC = dgvInt->RowCount-1;
             template <class Temp>
            /*array<TempArray^>^ massive;
            massive = gcnew array<TempArray^>(rowC);*/
             std::vector<TempArray>^ ptrofMass  = gcnew std::vector<TempArray^>(rowC);
 
         }
};
}
Код класса
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
 
template <class Temp>
class TempArray
{
private:
    int N;
    Temp* arr;
public:
    TempArray(int Count)
    {
        N = Count;
        Temp* arr = new Temp[N];
    }
 
    Temp& operator[](int index)
    {
        return arr[index];
    }
 
    ~TempArray(void)
    {
    delete[] arr;
    }
 
    friend bool operator==(TempArray &obj1, TempArray &obj2);
};
template <class Temp>
 
bool operator==(TempArray &obj1, TempArray &obj2)
{
    for(int i = 0;i<obj1.N;i++)
    {
        if(obj1.arr[i]!=obj2.arr[i])
            return false;   
    }
        return true;
}
template <class Temp>
 
bool operator!=(TempArray &obj1, TempArray &obj2)
{
    int reps = 0;
    for(int i = 0;i<obj1.N;i++)
    {
        if(obj1.arr[i] == obj2.arr[i])
            reps++;
    }
    if(reps == obj1.N)
    {
        return false;
    }
    else return true;
}

Заранее спасибо!
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
27.05.2021, 16:07
Ответы с готовыми решениями:

Хранение неинициализированных объектов шаблонного класса
Допустим, есть шаблонный класс template &lt;typename T&gt; class SomeValue; который хранит в себе...

Как корректно передать в метод шаблонного класса объект шаблонного класса в качестве параметра?
header.h template &lt;class T&gt; class MyVector { public: void swap(MyVector&lt;T&gt;Vector); }...

Возможно ли создание объекта шаблонного класса в функции этого класса?
Доброго времени суток, уважаемые форумчане :) Мне по лабам задали задание - реализовать шаблон...

Создание массива объектов класса
Доброго времени суток! Хотела бы разобраться с вашей помощью в чем-таки состоит моя ошибка. ...

1
1449 / 1121 / 347
Регистрация: 11.04.2011
Сообщений: 2,621
02.06.2021, 12:44 2
Цитата Сообщение от Chisellk0 Посмотреть сообщение
В ходе выполнения работы столкнулся с потребностью в создании динамического массива объектов шаблонного класса. Но вот беда, создать через array<TempArray^>^ arr = gcnew array<TempArray^>(10) не получается.
Подскажите еще какой-либо метод написания массива объектов шаблонного класса пожалуйта.
Был бы текст ошибки - было бы проще. Можно попробовать так:
C++
1
array<TempArray*>^ arr = gcnew array<TempArray*>(10)
Управляемые классы должны объявляться при помощи ref class. Ваш TempArray объявлен при помощи class, а значит знак карет (^) к нему не применим.
0
02.06.2021, 12:44
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
02.06.2021, 12:44
Помогаю со студенческими работами здесь

Создание Массива Объектов класса
Здравствуйте, такая вот проблемка возникла: нужно создать массив B объектов класса TGoods. И...

Создание массива объектов класса
Здравствуйте Подскажите пожалуйста как правилььно создать массив объектов класса, что бы не...

Создание массива объектов класса
Создание массива объектов класса. E2451 Undefined symbol 'myZKH' По-разному уже...

Создание Шаблонного класса
Здравствуйте! Столкнулся с проблемой создания шаблона для класса. Не могу понять как ввести более...

Создание двумерного массива объектов класса Cell
начал изучать ООП, и возник вопрос с разбором программы: #define EMPTY 0x00 typedef...

Создание шаблонного класса matrix
main.cpp #include &lt;iostream&gt; #include &quot;CMatrix.h&quot; int main() { int n = 3; int m = 2;


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru