Could there be a setting in Visual Studio 8 that might be causing this?
Mabe a linker, incude file, or debug setting.
When I was working on sketcher I would get only one or two errors that I could fix and then on the third compile I got 284 errors. The errors don't make any sense to me. Has the language changed sinse I baught this book?
I have a hunch it might have something to do with include files and Microsoft DirectX SDK (February 2007)which I installed prior to installing Visual Studio 8. Maybe VS 8 is looking in the wrong place for include files.
Here is my code try it yourself and see if you get the same errors.
// Header filr box.h in project Ex9_01
#pragma once
class CBox
{
public:
double m_Length;
double m_Width;
double m_Height;
CBox(double lv = 1.0, double wv = 1.0, double hv = 1.0):
m_Length(lv), m_Width(wv), m_Height(hv){}
};
// Header file CandyBox.h in project Ex9_01
#pragma once
#include "box.h"
class CCandybox: CBox
{
public:
char* m_Contents;
CCandyBox(char* str = "Candy") // Constructor
{
m_Contents = new char[ strlen(str) + 1 ];
strcpy_s(m_Contents, strlen(str) + 1, str);
}
~CCandyBox()
{ delete[] m_Contents; };
};
// Ex9_01.cpp
// Using a derived class
#include <iostream> // For stream I/O
#include <cstring> // For strlen() and strcpy()
#include "CandyBox.h" // For CBox and CCandyBox
using std::cout;
using std::endl;
int main()
{
CBox myBox(4.0, 3.0, 2.0); // Create CBox object
CCandyBox myCandyBox;
CCandyBox myMintBox("Wafer Thin Mints"); // Create CCandyBox object
cout << endl
<< "myBox occupies " << sizeof myBox // Show how much memory
<< " bytes" << endl // the objects require
<< "myCandyBox occupies " << sizeof myCandyBox
<< " bytes" << endl
<< "myMintBox occupies " << sizeof myMintBox
<< " bytes";
cout << endl
<< "myBox length is " << myBox.m_Length;
myBox.m_Length = 10.0;
// myCandyBox.m_Length = 10.0; // uncomment this for an error
cout << endl;
return 0;
}
|