(10%) Determine
whether the following code has syntax errors or not. If
it is correct, predict its output. If it is incorrect, point out
the mistake(s).
// Class Inheritance
#include <iostream>
class CBox
{
public:
CBox(double lv = 1.0, double wv = 1.0, double hv = 1.0):
m_Length(lv), m_Width(wv), m_Height(hv){}
private:
double m_Length;
double m_Width;
double m_Height;
};
class CCandyBox: CBox
{
public:
char* m_Contents;
// Function to calculate the volume of a CCandyBox object
double Volume() const // Error - members not accessible
{ return m_Length*m_Width*m_Height; }
CCandyBox(char* str = "Candy") // Constructor
{
m_Contents = new char[ strlen(str) + 1 ];
strcpy_s(m_Contents, strlen(str)+1, str);
}
~CCandyBox() // Destructor
{ delete[] m_Contents; };
};
int main()
{
CCandyBox aBox;
std::cout << aBox.Volume() << std::endl;
return 0;
}