ik ben een beetje aan het prutsen met Arrays in c++.net maar zit nu helemaal vast.
main.cpp file
en de hederfile hfile.h
Hij blijft misgaan op 'return month[MonthNumber];' Terwijl de array toch werkelijk aangemaakt wordt in de constructor
iemand enig idee (ja ik heb al gezocht maar kan niets vinden)
main.cpp file
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| #using <mscorlib.dll>
#include "hfile.h"
using namespace System;
int main(){
int intMonth=0;
Months *daysInMonth = new Months;
//daysInMonth->AssingMonth(4);
//Console::WriteLine(daysInMonth->GetDaysInMonth());
while (intMonth!=-1){
daysInMonth->AssingMonth(intMonth);
Console::WriteLine(daysInMonth->GetDaysInMonth());
intMonth=Convert::ToInt16(Console::ReadLine());
}
return 0;
} |
en de hederfile hfile.h
code:
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
| __gc class Months{
public:
Months();
int GetDaysInMonth();
void AssingMonth(int);
private:
int month __gc[];
int MonthNumber;
};
Months::Months(){
MonthNumber=1;
int month __gc[] = new int __gc[12];
month[0]=10;
month[1]=20;
month[2]=30;
month[3]=40;
month[4]=50;
month[5]=60;
month[6]=70;
month[7]=80;
month[8]=90;
month[9]=100;
month[10]=110;
month[11]=120;
}
int Months::GetDaysInMonth(){
return month[MonthNumber];
}
void Months::AssingMonth(int month){
MonthNumber=month;
} |
Hij blijft misgaan op 'return month[MonthNumber];' Terwijl de array toch werkelijk aangemaakt wordt in de constructor