The document asks how to declare constructors in a class header file and provides an example class called List. The summary is:
1) The List class constructor and other member functions like insert(), erase(), empty(), size(), get(), and display() need to be declared in the header file.
2) The constructor is declared as List(); without any parameters since it initializes the size and array.
3) Member variables like mySize and myArray also need to be declared in the header file since other functions access them.
Making communications land - Are they received and understood as intended? we...
How do I declare the following constructors in my .h file Below.pdf
1. How do I declare the following constructors in my .h file?
Below was the original code.
#include const int CAPACITY =1024; using namespace std; typedef int ElementType; // Now
"ElementType" is "int" L//can change int to double, char,... class List { public: List();
//constructor unsigned size() const; bool empty() const; //check if empty void
insert(ElementType item, int pos); //insertion void erase(int pos); //deletion void
display(ostream& out) const; //display every item ElementType get(unsigned pos) const;
private: int mySize; // current # of items in list int myArray[CAPACITY]; No issues found 4
Error List Entire
Solution
(i) 0 Messages Q7 Build + IntelliSense " Code Description abc E0135 class "List" has no
member "removeAll" abc E0020 identifier "myArray" is undefined abc E0020 identifier
"mySize" is undefined abc E0020 identifier "mySize" is undefined abc E0493 no instance of
overloaded function "List::List" matches the specified type
#include #include cstdlib> #include "list.h" using namespace std; void List: :
insert(ElementType item, int pos) { if (mySize == CAPACITY) exit(1); if (pos< 0|| pos >
mysize) return; // shift array elements right to make room for for (int i= mysize; i> pos; i )
myArray[i]=myArray[i1]; // insert item at pos and increase list size myArray [pos] = item;
mySize++; // don't forget this! } void List: :erase(int pos) { if (pos<0 || pos >= mySize) return;
// shift array elements left for (int i= pos; i < mysize-1; i++ ) myArray[i]=myArray[i+1]; }
mySize--; // don't forget this! List: : List( ) { mySize =0; } bool List: :empty() const { return
(mySize ==0 ); } unsigned List::size() const { return mysize; } ElementType List:
:get(unsigned pos) const { if (pos >= mysize) { cerr "Invalid Index." endl; exit(1); } return
myArray[pos]; } void List: : display(ostream & out) const { for (int i=0; i