sccheung
asked on
What's wrong?
What's wrong with the following statement?
public:
CTypedPtrArray<CObArray, CTypedPtrArray<CObArray, MyObject&>&> My2DObArray;
I get missing "decl-specifiers" error, "syntax error : missing ';' before '<'", "unexpected token(s) preceding ';'". The lines are from my header file of my control. I add these lines after the lines generate by MSVC. I get errors even if I use 1D CArrays of CString there! Why?
public:
CTypedPtrArray<CObArray, CTypedPtrArray<CObArray, MyObject&>&> My2DObArray;
I get missing "decl-specifiers" error, "syntax error : missing ';' before '<'", "unexpected token(s) preceding ';'". The lines are from my header file of my control. I add these lines after the lines generate by MSVC. I get errors even if I use 1D CArrays of CString there! Why?
Try to add spaces before and/or after the brackets.
I've had similar problem before and it helped.
Laurent.
I've had similar problem before and it helped.
Laurent.
ASKER
I'm very sorry to tell you that it doesn't work. It seems that you need more information. I give you the entire header file:
//Header file starts here:
#if !defined(AFX_MAGICSQUARENU MBERBLOCKC ONTAINERCT L_H__0FA1C 38C_6688_1 1D1_A3CF_E 58E3C69845 A__INCLUDE D_)
#define AFX_MAGICSQUARENUMBERBLOCK CONTAINERC TL_H__0FA1 C38C_6688_ 11D1_A3CF_ E58E3C6984 5A__INCLUD ED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// MagicSquareNumberBlockCont ainerCtl.h : Declaration of the CMagicSquareNumberBlockCon tainerCtrl ActiveX Control class.
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
// CMagicSquareNumberBlockCon tainerCtrl : See MagicSquareNumberBlockCont ainerCtl.c pp for implementation.
class CMagicSquareNumberBlockCon tainerCtrl : public COleControl
{
DECLARE_DYNCREATE(CMagicSq uareNumber BlockConta inerCtrl)
// Constructor
public:
CMagicSquareNumberBlockCon tainerCtrl ();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMagicSqua reNumberBl ockContain erCtrl)
public:
virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);
virtual void DoPropExchange(CPropExchan ge* pPX);
virtual void OnResetState();
//}}AFX_VIRTUAL
// Implementation
protected:
~CMagicSquareNumberBlockCo ntainerCtr l();
DECLARE_OLECREATE_EX(CMagi cSquareNum berBlockCo ntainerCtr l) // Class factory and guid
DECLARE_OLETYPELIB(CMagicS quareNumbe rBlockCont ainerCtrl) // GetTypeInfo
DECLARE_PROPPAGEIDS(CMagic SquareNumb erBlockCon tainerCtrl ) // Property page IDs
DECLARE_OLECTLTYPE(CMagicS quareNumbe rBlockCont ainerCtrl) // Type name and misc status
// Message maps
//{{AFX_MSG(CMagicSquareNu mberBlockC ontainerCt rl)
// NOTE - ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
// Dispatch maps
//{{AFX_DISPATCH(CMagicSqu areNumberB lockContai nerCtrl)
short m_blockSize;
afx_msg void OnBlockSizeChanged();
short m_blocksPerRow;
afx_msg void OnBlocksPerRowChanged();
short m_blocksPerColumn;
afx_msg void OnBlocksPerColumnChanged() ;
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
afx_msg void AboutBox();
// Event maps
//{{AFX_EVENT(CMagicSquare NumberBloc kContainer Ctrl)
//}}AFX_EVENT
DECLARE_EVENT_MAP()
// Dispatch and event IDs
public:
enum {
//{{AFX_DISP_ID(CMagicSqua reNumberBl ockContain erCtrl)
dispidBlockSize = 1L,
dispidBlocksPerRow = 2L,
dispidBlocksPerColumn = 3L,
//}}AFX_DISP_ID
};
// The 2D object array of number block
public:
//problem begins here
CTypedPtrArray< CObArray, CTypedPtrArray< CObArray, CMagicSquareNumberBlocks& >& > TheNumberBlocks;
//problem ends here
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MAGICSQUARENU MBERBLOCKC ONTAINERCT L_H__0FA1C 38C_6688_1 1D1_A3CF_E 58E3C69845 A__INCLUDE D)
//Header file ends here.
That line is to declare a 2D array of number block which is a CObject containing the value of the block. That TObject is also responsible for displaying the block. As I want to let the user to pull the blocks is the game, the blocks have to be individual CObjects. In fact, that CObject is a ActiveX Control written with the ActiveX ControlWizard. I want to tell you that I know Delphi but is new to MSVC++. I make this program to get used to VC. Therefore the problems may be caused by some very silly mistakes. If anyone knows a better solution to this problem then declaring a 2D Object Array, you may also tell me. However, I find both CTypedPtrArray and 2D array very useful and I want to learn how to use both of them at the same time.
It's quite inconvenient to write "xxx start here" and "xxx ends here". Do you know how to use bold or italic in experts exchange?
//Header file starts here:
#if !defined(AFX_MAGICSQUARENU
#define AFX_MAGICSQUARENUMBERBLOCK
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// MagicSquareNumberBlockCont
//////////////////////////
// CMagicSquareNumberBlockCon
class CMagicSquareNumberBlockCon
{
DECLARE_DYNCREATE(CMagicSq
// Constructor
public:
CMagicSquareNumberBlockCon
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMagicSqua
public:
virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);
virtual void DoPropExchange(CPropExchan
virtual void OnResetState();
//}}AFX_VIRTUAL
// Implementation
protected:
~CMagicSquareNumberBlockCo
DECLARE_OLECREATE_EX(CMagi
DECLARE_OLETYPELIB(CMagicS
DECLARE_PROPPAGEIDS(CMagic
DECLARE_OLECTLTYPE(CMagicS
// Message maps
//{{AFX_MSG(CMagicSquareNu
// NOTE - ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
// Dispatch maps
//{{AFX_DISPATCH(CMagicSqu
short m_blockSize;
afx_msg void OnBlockSizeChanged();
short m_blocksPerRow;
afx_msg void OnBlocksPerRowChanged();
short m_blocksPerColumn;
afx_msg void OnBlocksPerColumnChanged()
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
afx_msg void AboutBox();
// Event maps
//{{AFX_EVENT(CMagicSquare
//}}AFX_EVENT
DECLARE_EVENT_MAP()
// Dispatch and event IDs
public:
enum {
//{{AFX_DISP_ID(CMagicSqua
dispidBlockSize = 1L,
dispidBlocksPerRow = 2L,
dispidBlocksPerColumn = 3L,
//}}AFX_DISP_ID
};
// The 2D object array of number block
public:
//problem begins here
CTypedPtrArray< CObArray, CTypedPtrArray< CObArray, CMagicSquareNumberBlocks& >& > TheNumberBlocks;
//problem ends here
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MAGICSQUARENU
//Header file ends here.
That line is to declare a 2D array of number block which is a CObject containing the value of the block. That TObject is also responsible for displaying the block. As I want to let the user to pull the blocks is the game, the blocks have to be individual CObjects. In fact, that CObject is a ActiveX Control written with the ActiveX ControlWizard. I want to tell you that I know Delphi but is new to MSVC++. I make this program to get used to VC. Therefore the problems may be caused by some very silly mistakes. If anyone knows a better solution to this problem then declaring a 2D Object Array, you may also tell me. However, I find both CTypedPtrArray and 2D array very useful and I want to learn how to use both of them at the same time.
It's quite inconvenient to write "xxx start here" and "xxx ends here". Do you know how to use bold or italic in experts exchange?
Try to use pointer instead of reference!
CTypedPtrArray< CObArray, CTypedPtrArray< CObArray, CMagicSquareNumberBlocks* >* > TheNumberBlocks;
CTypedPtrArray< CObArray, CTypedPtrArray< CObArray, CMagicSquareNumberBlocks* >* > TheNumberBlocks;
ASKER
Trying... Please wait for a minute.
ASKER
The same error still occur! Is this question too difficult? Should I use another method besides OBArray to solve this problem?
ASKER
I suceeded at last! I have been trying to fix this error for over a week. I am so excited when MSVC++ reports "0 errors, 0 warnings". With reference to the collect sample from MFC, I know that I have to add #include <afxtmpl> in the file stdafx.h to include the template support including the CTypedPtrArray. As I have told you before, the problem is caused by my lack of basic MFC knowledge. But why is there no book or MFC help file which tell me about this?
After adding this line, I find that I still have to take Tulin's advice and change it into pointer. Therefore, I would like to give the points to Tulin despite the fact that he cannot solve my problem completely. Tulin, please re-send your answer to let me grade it and give you the points.
After adding this line, I find that I still have to take Tulin's advice and change it into pointer. Therefore, I would like to give the points to Tulin despite the fact that he cannot solve my problem completely. Tulin, please re-send your answer to let me grade it and give you the points.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
anyway, CTypedPtrArray and MyObject seems to be a type variable (as int or char). CObArray and My2DObArray seems to be variables, but not sure at all!!
try searching for the declaration of the type variables.
if you need some more help try posting those declaration, and a piece of code that shows the use of CObArray and My2DObArray in action... ok!?
rigansen.