Reputation: 410
its part of code:
class WierszTrojkatPascala { //tab,tablica is an array
private:
int tablica[];
public:
WierszTrojkatPascala(int n) {
int* tab = new int[n+1];
for(int i=0;i<n+1;i++)
tab[i] = 0;
tab[0] = 1;
//creating pascal triangle for n//
for( int i=0; i<=n; i++)
for( int j=i; j>0; j--)
tab[j]=tab[j]+tab[j-1];
for(int i=0;i<=n;i++)
cout<<tab[i]<<' ';
for(int i=0;i<=n;i++)
tablica[i]=tab[i];
}
int wspolczynnik(int m) {
return tablica[m];
}
};
This class creates n'th verse of pascal triangle. In the rest part of code i want to use wpspolczynnik function. Unfortunatelty tablica[m] doesnt work. For instance when i create an object of class WierszTrojkataPascala verse
and do verse.wspolczynnik(1)
i am getting return equal to 2 but it should be 4. Why my verse is made correct by constructor but when i am trying to get to it by function wspolczynik() it doesnt work.
Ty in advance!
Upvotes: 0
Views: 55
Reputation: 310990
This definition of data member tablica
int tablica[];
is invalid. You have to specify the size of the array using a const expression.
Upvotes: 2