So I have this problem, I have just started learning DirectX 9 with the Strategy Game Programming with DirectX 9.0 book, I have a header including this code:

class TileClass
{
   private:
      int*m_iValue;
      int m_iNumLayers;
      float *m_fRotX;
      float *m_fSize;

   public:
      TileClass();
      ~TileClass();
      int iGetValue(int layer);
      void vSetValue(int value, int layer);
      float fGetRot(int layer);
      void vSetRotation(float fRot, int layer);
      float fGetSize(int layer);
      void vSetSize(float fSize, int layer);
      void vSetNumLayers(int layers);
};

And I'm including the header in my .CPP file, I have also included this code as the book told me to:

// Constructor
TileClass::TileClass()
{
   // Initialize internal vars
   m_iNumLayers = 0;
   m_iValue = NULL;
   m_fRotX = NULL;
   m_fSize = NULL;
}
// Destructor
TileClass::~TileClass()
{
   // Free layer buffer if already allocated
   if(m_iValue)
      delete [] m_iValue;
   if(m_fRotX)
      delete [] m_ fRotX;
   if(m_fSize)
      delete [] m_ fSize;
}
// Set number of layers
void TileClass::vSetNumLayers(int layers)
{
   // Free layer buffer if already allocated
   if(m_iValue)
      delete [] m_iValue;
   if(m_fRotX)
      delete [] m_fRotX;
   if(m_fSize)
      delete [] m_fSize;
   // Allocate memory for layer buffer
   m_iValue = new int[layers];
   memset(m_iValue,0,layers*sizeof(int));

   m_fRotX = new float[layers];
   memset(m_fRotX,0,layers*sizeof(int));

   m_fSize = new float[layers];
   memset(m_fSize,0,layers*sizeof(int));

   // Set the number of layers
   m_iNumLayers = layers;
}
// Get value of the tile
int TileClass::iGetValue(int layer)
{
   // Make sure not trying to retrieve illegal layer
   if(layer >= m_iNumLayers) {
      return(-1);
   }
   // Return the value
   return(m_iValue[layer]);
}
// Set the tile's value
void TileClass::vSetValue(int value, int layer)
{
   // Make sure not trying to use an illegal layer
   if(layer >= m_iNumLayers) {
      return;
   }
   // Set the value
   m_iValue[layer] = value;
}
// Set the rotation
void TileClass::vSetRotation(float fRot, int layer)
{
   // Make sure not trying to use an illegal layer
   if(layer >= m_iNumLayers) {
      return;
   }
   m_fRotX[layer] = fRot;
}
// Set the size
void TileClass::vSetSize(float fSize, int layer)
{
   // Make sure not trying to use an illegal layer
   if(layer >= m_iNumLayers) {
      return;
   }
   m_fSize[layer] = fSize;
}
// Get the rotation
float TileClass::fGetRot(int layer)
{
   // Make sure not trying to use an illegal layer
   if(layer >= m_iNumLayers) {
      return(-1.0f);
   }
   return(m_fRotX[layer]);
}
// Get the size
float TileClass::fGetSize(int layer)
{
   // Make sure not trying to use an illegal layer
   if(layer >= m_iNumLayers) {
      return(-1.0f);
   }
   return(m_fSize[layer]);
}

But I still get these errors:

1>------ Build started: Project: CreateWindow, Configuration: Debug Win32 ------
1>Compiling...
1>DirectX.cpp
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(20) : warning C4822: 'Main::TileClass::TileClass' : local class member function does not have a body
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(21) : warning C4822: 'Main::TileClass::~TileClass' : local class member function does not have a body
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(22) : warning C4822: 'Main::TileClass::iGetValue' : local class member function does not have a body
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(23) : warning C4822: 'Main::TileClass::vSetValue' : local class member function does not have a body
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(24) : warning C4822: 'Main::TileClass::fGetRot' : local class member function does not have a body
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(25) : warning C4822: 'Main::TileClass::vSetRotation' : local class member function does not have a body
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(26) : warning C4822: 'Main::TileClass::fGetSize' : local class member function does not have a body
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(27) : warning C4822: 'Main::TileClass::vSetSize' : local class member function does not have a body
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(28) : warning C4822: 'Main::TileClass::vSetNumLayers' : local class member function does not have a body
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(64) : error C2143: syntax error : missing ';' before '{'
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(66) : error C2065: 'm_iNumLayers' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(67) : error C2065: 'm_iValue' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(68) : error C2065: 'm_fRotX' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(69) : error C2065: 'm_fSize' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(72) : error C2352: 'Main::TileClass::~TileClass' : illegal call of non-static member function
1>        c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(21) : see declaration of 'Main::TileClass::~TileClass'
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(73) : error C2143: syntax error : missing ';' before '{'
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(75) : error C2065: 'm_iValue' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(76) : error C2065: 'm_iValue' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(76) : error C2541: 'delete' : cannot delete objects that are not pointers
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(77) : error C2065: 'm_fRotX' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(78) : error C2065: 'm_' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(78) : error C2541: 'delete' : cannot delete objects that are not pointers
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(78) : error C2146: syntax error : missing ';' before identifier 'fRotX'
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(78) : error C2065: 'fRotX' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(79) : error C2065: 'm_fSize' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(80) : error C2065: 'm_' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(80) : error C2541: 'delete' : cannot delete objects that are not pointers
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(80) : error C2146: syntax error : missing ';' before identifier 'fSize'
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(80) : error C2065: 'fSize' : undeclared identifier
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(84) : error C2601: 'Main::TileClass::vSetNumLayers' : local function definitions are illegal
1>        c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(9): this line contains a '{' which has not yet been matched
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(107) : error C2601: 'Main::TileClass::iGetValue' : local function definitions are illegal
1>        c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(9): this line contains a '{' which has not yet been matched
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(117) : error C2601: 'Main::TileClass::vSetValue' : local function definitions are illegal
1>        c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(9): this line contains a '{' which has not yet been matched
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(127) : error C2601: 'Main::TileClass::vSetRotation' : local function definitions are illegal
1>        c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(9): this line contains a '{' which has not yet been matched
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(136) : error C2601: 'Main::TileClass::vSetSize' : local function definitions are illegal
1>        c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(9): this line contains a '{' which has not yet been matched
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(145) : error C2601: 'Main::TileClass::fGetRot' : local function definitions are illegal
1>        c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(9): this line contains a '{' which has not yet been matched
1>c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(154) : error C2601: 'Main::TileClass::fGetSize' : local function definitions are illegal
1>        c:\users\kouta\documents\visual studio 2008\projects\createwindow\createwindow\directx.cpp(9): this line contains a '{' which has not yet been matched

Thanks in advance.

P.S. I am using Visual C++ 2008.

Recommended Answers

All 2 Replies

Well, if I'm not mistaken, it looks like you define i.e your constructor as TileClass::TileClass() in your .h file, but in your .cpp file it looks like you're trying to implements Main::TileClass::TileClass() Which you haven't defined anywhere. Take a look at your main() function and its brackets. The main() function should be on its own, like

// Implementations first
TileClass::TileClass()
{
   // Initialize internal vars
   m_iNumLayers = 0;
   m_iValue = NULL;
   m_fRotX = NULL;
   m_fSize = NULL;
}

int main()
{
   // Some fancy stuff here
   return 0;
}

Or, if you have a class called Main (?) also check its brackets.

I hope this helps!
Emil Olofsson

Well, if I'm not mistaken, it looks like you define i.e your constructor as TileClass::TileClass() in your .h file, but in your .cpp file it looks like you're trying to implements Main::TileClass::TileClass() Which you haven't defined anywhere. Take a look at your main() function and its brackets. The main() function should be on its own, like

// Implementations first
TileClass::TileClass()
{
   // Initialize internal vars
   m_iNumLayers = 0;
   m_iValue = NULL;
   m_fRotX = NULL;
   m_fSize = NULL;
}

int main()
{
   // Some fancy stuff here
   return 0;
}

Or, if you have a class called Main (?) also check its brackets.

I hope this helps!
Emil Olofsson

I love you, in a totally gay way, but in all seriousness, thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.