
Class object as static member of another class
I want to use a CArray object as a static member of a class I have defined.
Within the header (.h) file I have...
class CPlayPiece : public CObject
{
protected:
// Lots of stuff...
public:
// More stuff...
// Static CArray member
static CArray<int, int> m_CArray_colorCounter;
Quote:
}; // class CPlayPiece : public Cobject
Then in the implementation (.cpp) file I have...
// Static member initialization
CArray<int, int> CPlayPiece::m_CArray_colorCounter;
// CPlayPiece::m_CArray_colorCounter.SetSize(200);
// Default constructor
CPlayPiece::CPlayPiece(const CRect & CRect_playSurface)
{
CPlayPiece::m_CArray_colorCounter.SetSize(200);
// More stuff
Quote:
}
In the .cpp file I have the variable, m_CArray_colorCounter, completely
qualified. However, when I try to set the size of the CArray object
immediately under the line, I get a bunch of errors...
error C2143: syntax error : missing ';' before '.'
error C2501: 'm_CArray_colorCounter' : missing storage-class or type
specifiers
error C2371: 'public: static class CArray<int,int>
CPlayPiece::m_CArray_colorCounter' : redefinition; different basic types
c:\myfiles\computer
related\vcpp_projects\general_3\tetris\playpiece.h(55) : see declaration
of 'public: static class CArray<int,int> CPlayPiece::m_CArray_colorCounter'
error C2143: syntax error : missing ';' before '.'
However, when I include the SetSize() function in the constructor it
compiles. My concern is that with each new instance of CPlayPiece the
array will be resized.
Why can I not set the size outside of the scope of the constructor? Is
this the correct way of using a class object as a static member of
another class?
Thanks.
Best regards,
Thomas