Hi anyone.
Please help with this seperate compilation.
Many thanks !
==================================
//pointerDataClass ;Header file
class pointerDataClass
{
public:
void print() const;
//Function to output the value of x and
//the value of the array p.
void setData();
//Function to input data into x and
//into the array p.
void destroyP();
//Function to deallocate the memory space
//occupied bt the array p.
pointerDataClass(int sizeP = 10);
//constructor
//Create an array of the size specified by the
//parameter sizeP; the default array size is 10.
~pointerDataClass();
//destructor
//Deallocate the memory space occupied by the array p.
pointerDataClass (const pointerDataClass& otherObject);
//copy constructor
private:
int x;
int lenP;
int *p; //pointer to an int array
};
//pointerDataClassIMP ; this is the implementation file
#include <iostream>
#include "pointerDataClass.h"
void pointerDataClass::print() const
{
cout << "x = " << x << endl;
cout << "p = ";
for (int i = 0; i < lenP; i++)
cout << p[i] << " ";
cout << endl;
}
void pointerDataClass::setData()
{
cout << "Enter an integer for x: ";
cin >> x;
cout << endl;
cout << "Enter " << lenP << " numbers: ";
for (int i = 0; i < lenP; i++)
cin >> p[i];
cout << endl;
}
void pointerDataClass::destroyP()
{
lenP = 0;
delete [] p;
p = NULL;
}
pointerDataClass::pointerDataClass(int sizeP)
{
x = 0;
if (sizeP <= 0)
{
cout << "Array size must be positive." << endl;
cout << "Creating an array of size 10." << endl;
lenP = 10;
}
else
lenP = sizeP;
p = new int[lenP];
assert(p != NULL);
}
pointerDataClass::~pointerDataClass()
{
delete [] p;
}
//copy constructor
pointerDataClass::pointerDataClass(const pointerDataClass& otherObject)
{
x = otherObject.x;
lenP = otherObject.lenP;
p = new int[lenP];
assert(p != NULL);
for (int i = 0; i < lenP; i++)
p[i] = otherObject.p[i];
}
#include <iostream>
#include "pointerDataClass.h"
using namespace std;
int main() {
pointerDataClass regClass;
regClass.setData();
regClass.print();
return 0;
}
The compiler is pointing to line 2 in Main.
Why?
Am i not including the header file correctly ??
Please advise.