0

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 verseand 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!

3
  • Object class members must have complete type. Commented Mar 17, 2014 at 21:29
  • Canned "I'm having trouble with arrays in C++" response: Use std::vector. Commented Mar 17, 2014 at 21:30
  • ty u!!!! vector worked! Commented Mar 17, 2014 at 21:46

1 Answer 1

2

This definition of data member tablica

int tablica[];

is invalid. You have to specify the size of the array using a const expression.

Sign up to request clarification or add additional context in comments.

2 Comments

So how to use tab in function wspolczynnik()?
@user3402584 I have not understood the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.