[c++.net] probleempje met arrays in class

Pagina: 1
Acties:
  • 31 views sinds 30-01-2008

  • Vampier
  • Registratie: Februari 2001
  • Laatst online: 20-04-2015

Vampier

poke-1,170

Topicstarter
ik ben een beetje aan het prutsen met Arrays in c++.net maar zit nu helemaal vast.

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 :'( iemand enig idee (ja ik heb al gezocht maar kan niets vinden)

  • Vampier
  • Registratie: Februari 2001
  • Laatst online: 20-04-2015

Vampier

poke-1,170

Topicstarter
laat maar ... in Months::Months() moet ik niet nogmaals het type declateren...

deze kan opslot (sorry zag het opeens wel)

Verwijderd

Assign ipv Assing....

  • Vampier
  • Registratie: Februari 2001
  • Laatst online: 20-04-2015

Vampier

poke-1,170

Topicstarter
LOL dat ook nog ;)

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 12-05 22:23

curry684

left part of the evil twins

Anders debug je de volgende keer even zelf voordat je een topic opent.... :?

Professionele website nodig?


Dit topic is gesloten.