dynamic array problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blackstormdragon
    New Member
    • Feb 2007
    • 32

    #1

    dynamic array problems

    I have a feeling I'm doing this whole dynamic array thing wrong, or Im misunderstandin g it.
    Code:
    private:
    	int degree;
    	int numCoef;
    	double *coef;
    
    Polynomial::Polynomial( int hdegree)
    {
    	degree = hdegree;
    	numCoef = degree + 1;
    	coef = new double [numCoef];
    	FillCoef();
    }
    These are just some snipits of code. When coef creates a new double, all I get is a one element array. No matter what is put in. I have a feeling I'm very confused, helps very appreciated.
    Thanks
  • rhitam30111985
    New Member
    • Aug 2007
    • 112

    #2
    it is possible there is some error in the fillcoef() function.. which i guess inserts values in the the dynamic array .. could u post the relevant insertion fucntion so that u get better help?

    regards
    Rhitam

    Comment

    • kaioshin00
      New Member
      • Nov 2006
      • 46

      #3
      Originally posted by blackstormdrago n
      I have a feeling I'm doing this whole dynamic array thing wrong, or Im misunderstandin g it.
      Code:
      private:
      	int degree;
      	int numCoef;
      	double *coef;
      
      Polynomial::Polynomial( int hdegree)
      {
      	degree = hdegree;
      	numCoef = degree + 1;
      	coef = new double [numCoef];
      	FillCoef();
      }
      These are just some snipits of code. When coef creates a new double, all I get is a one element array. No matter what is put in. I have a feeling I'm very confused, helps very appreciated.
      Thanks
      How are you determining that it's a one element array?

      Comment

      • blackstormdragon
        New Member
        • Feb 2007
        • 32

        #4
        Heres the code for filling the array.
        Code:
        int c;
        
        	for(int index =0; index < numCoef ;index++)
        	{
        		cout<<"What coefficient do you want for x^"<<index<<": ";
        		cin>>c;
        		coef[index] = c;
        	}
        	cout<<endl;
        When I debugg using f10, I can look at the elements in coef and there is only ever one element.

        *EDIT: I have a feeling every thing works Ok. I think I just don't understand pointers fully. I say this becuase now that my cout overload works everything is prinitng ok. So this problem is fixed, now I just have to fix my +- and * overload statments. Thanks for the help.

        Comment

        Working...