I am learning about contructors and keep getting errors

// construct and destruct
#include <iostream>
using namespace std;
class clsFish
{
private:
int iSize1; // size for dynamic array
int * pLocC; // create int pointer look

public:
clsFish (int iSize2)// replace dynamic array
{
iSize1 = iSize2; // use parameter
if (iSize2 > 0)
{
pLocC = new int(iSize2);
for(int iPos =0; iPos < iSize2; iPos++)
{ // intialize dynamic array
pLocC[iPos] = iPos *2;
}
}

}
~clsFish()
{
if (iSize1 > 0)
{
delete [] pLocC;
}
}
void Display()
{
for(int iPos =0; iPos < iSize2; iPos++)
{ // intialize dynamic array
cout << iPos << ": " << &pLocC[iPos] << ": "<< &pLocC[iPos] << endl;
}
}

};

int main()
{
clsFish objGoldFish;
objGoldFish.Display();
char cPause;
cin >> cPause;
return 0;

}






// here is my code it keeps telling me that my that iSize2 is not declared. I am using Dev c++ and it keeps giving me errors and am wondering if any one can help me out. It would be greatly appreciated.
Last edited on
In your display function you try to use iSize2 but you don't pass iSize2 into the display function, you pass iSize2 into the constructor and assign iSize1 its value. Use iSize1 in the for loop in Display()
Topic archived. No new replies allowed.