I am doing an assignment for my OOP C++ class. I am currently struggling with initializing a pointer. The directions for my assignment from this part state:
Define a class called FracList with private members fracPtr, a Fraction pointer and size to hold the size of the array of Fraction objects.
My current code, which brings errors, goes like this. Note Fraction
is another class.
in FracList.h
private:
Fraction *fracPtr;
int size;
in FracList.cpp
void FracList::set_ptr(int* p)
{
fracPtr = p;
}
Fraction *FracList::get_ptr()
{
return fracPtr;
}
// Default Constructor
FracList::FracList(int s) : size(s)
{
if (size > 0)
fracPtr = new Fraction[size];
else
fracPtr = NULL;
}
How do I properly initialize the Fraction* fracPtr
pointer variable?