c++ - Why does not see the array in the same class? -
i want write polynomial class,each polynomial consist of multi poly have implemented array, code:
class polynomial { private: int count; public: polynomial() { count = 0; term terms[10]; } void create(int c) { terms[count].coef = c; } }; class term { public: double coef; int expo; };
i have problem in create method,it not know terms array , not access term object properties. why happen?
// first declare class referenced class term { public: double coef; int expo; }; class polynomial { private: int count; // terms should class member not local of constructor term terms[10]; public: polynomial() { count = 0; // if declare terms array here // destroy after returns constructor // term terms[10]; } void create(int c) { terms[count].coef = c; } };
if polynomial declaration before term declaration requirement forward declaration can used as:
class term; class polynomial { ... }; class term { // real declaration here };
but not revoke wrong terms
definition in constructor instead of class member.
Comments
Post a Comment