Hi,
I am fairly new to c++/oop but not to programming. In my current project, I have already written a class for complex numbers wich works reliably. I am now trying to write a class for complex polynomials using complex objects as the coeficients. Because the order of the polynomial will not be known until run time, I need to dynamically allocate an array of complex numbers to represent the coeficients. I would like this array to operate as an attribute of the polynomial class. My questions/problems are these:
1.) I am unsure how to handle the declaration in the .h file. I have tried leaving this out as well as
Code:
complex *coef = new complex[];
And
Code:
complex *coef = new complex[order];
Where order is another attribute defined in the constructor and prototyped imediately above
Within the .cpp file my code appears as:
Code:
//implement constructors
poly::poly(unsigned int a)
{
order = a;
//allocate an array of complex objects as coefficients
complex *coef = new complex[order];
}
My goal is to creat the pointer so that I can use it in a for loop external to creat objects in the complex class in order to set the value of the coefficients.
Without any form of declaration I get the expected
error C2065: 'coef' : undeclared identifier
With the declaration I get the much more forboding:
error C2864: 'poly::coef' : only static const integral data members can be initialized within a class
This leads me to believe that what I would like to do may not be possible, which seems odd
Can anyone please suggest any ways in which I might fix these errors or restructure the program in a legal manner.
Thank you in advance.
Carl