I have to use provided parent classes to create a class called inventory. When i try to compile I get
error C2352: 'Lumber::getlumber' : illegal call of non-static member function
Im really ranking my brain on this one. I am not allowed to make any changes to the parents.How can i call a memberfunction without having to be static?
Code:The provided class definitions // program_id LUMBER.H // written_by Hi Lo Jo // company The Woods of Colorado Springs, CO // // description This header file contains the class definitions // needed for the program: STORELUMBER.CPP. // The method definitions are in the file LUMBER.CPP // #ifndef LUMBER #define LUMBER const short LEN = 40; // maximum length of strings class Type // type of lumber { private: char dimensions[LEN]; char grade[LEN]; public: Type(); // constructor (no args) Type(char di[], char gr[]); // constructor (two args) void gettype(); // get type from user void showtype(); // display type char * show_grade(); // displays the grade char * show_dimensions(); // displays the dimensions }; class Distance // English Distance class { private: short feet; double inches; public: Distance(); // constructor (no args) Distance(short ft, double in); // constructor (two args) void getdist(); // get length from user int show_feet(); // shows the feet double show_inches(); // shows the inches void showdist(); // display distance }; class Lumber : public Type, public Distance { private: short quantity; // number of pieces double price; // price of each piece public: Lumber(); // constructor (no args) // constructor (6 args) Lumber( char di[], char gr[], // args for Type short ft, double in, // args for Distance short qu, double prc ); void getlumber(); // gets from the keyboard the lumber values void showlumber(); // displays on the screen the values int show_quantity(); // diplays on the screen the quantity double show_price(); // diplays on the screen the price }; #endif }
Code:The provided class method definitions, i cut out a lot to save some space // program_id LUMBER.CPP // written_by Hi Lo Jo // company The Woods of Colorado Springs, CO // // description This file contains the class method definitions // needed for the program: STORELUMBER.CPP. // The class definitions are in the file LUMBER.H #include<iostream> #include<string> using namespace std; #include"lumber.h" // type of lumber function definitions Type::Type() // constructor (no args) { strcpy(dimensions, "N/A"); strcpy(grade, "N/A"); } Type::Type(char di[], char gr[]) // constructor (two args) { strcpy(dimensions, di); strcpy(grade, gr); } void Type::gettype() // get type from user { cout << " Enter nominal dimensions (2x4 etc.): "; cin >> dimensions; cout << " Enter grade (rough, const, etc.): "; cin >> grade; } void Type::showtype() // display type { cout << "\n Dimensions: " << dimensions; cout << "\n Grade: " << grade; } char * Type::show_grade() { return grade; } char * Type::show_dimensions() { return dimensions; } // Distance class function definitions Distance::Distance() // constructor (no args) { feet = 0; inches = 0.0; } Distance::Distance(short ft, double in) // constructor (two args) { feet = ft; inches = in; } void Distance::getdist() // get length from user { cout << " Enter feet: "; cin >> feet; cout << " Enter inches: "; cin >> inches; } void Distance::showdist() // display distance { cout << feet << "\'-" << inches << '\"'; } int Distance::show_feet() { return feet; } double Distance::show_inches() { return inches; } // Lumber class function definitions Lumber::Lumber() : Type(), Distance() // constructor (no args) { quantity = 0; price = 0.0; } // constructor (6 args) Lumber::Lumber( char di[], char gr[], // args for Type short ft, double in, // args for Distance short qu, double prc ) : // our own args Type(di, gr), // call Type constructor Distance(ft, in) // call Distance constr { quantity = qu; price = prc; // use our own args } void Lumber::getlumber() { Type::gettype(); Distance::getdist(); cout << " Enter quantity: "; cin >> quantity; cout << " Enter price per piece: "; cin >> price; }
Code:class i wrote that uses the parents lumber and date, i did not attach date //newLumber.h #include "lumber.h" #include "date.cpp" #ifndef INVENTORY #define INVENTORY //Derived class from parents lumber and date class inventory : public LUMBER DATE { private: long inventoryNumber; protected: public: inventory(); void enterSku(); }; #endifCode:Class member functions //newLumber.cpp #include <iostream> #include "newLumber.h" using namespace std; //member function that will create a new sku void inventory::enterSku() { cout << "What is the SKU number?" << endl; cin >> inventoryNumber; Lumber::getlumber(); }



LinkBack URL
About LinkBacks
How can i call a memberfunction without having to be static?



I used to be an adventurer like you... then I took an arrow to the knee.