Title: | Microsoft Visual C/C++ |
Moderator: | PLUGH::needle |
Created: | Tue Mar 16 1993 |
Last Modified: | Wed Jun 04 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 1121 |
Total number of notes: | 4385 |
HI all, while trying to learn MFC prpgramming I followed the scribble example supplied in VC++4.2 installation (books online/Visual C++ books/Tutorials/...) I strictly followed the indication on the documenation copying and pasting the code supplied in the sections of the docs. When I tried the compilation I received the following errors: Compiling... scribbleDoc.cpp C:\MSDEV\MFC\include\afxtempl.h(1561) : error C2664: 'struct __POSITION *CObList::AddHead(class CObject *)' : cannot convert parameter 1 from 'class CStroke *' to 'class CObject *' (new behavior; please see help) C:\MSDEV\MFC\include\afxtempl.h(1563) : error C2664: 'struct __POSITION *CObList::AddTail(class CObject *)' : cannot convert parameter 1 from 'class CStroke *' to 'class CObject *' (new behavior; please see help) C:\MSDEV\MFC\include\afxtempl.h(1587) : error C2664: 'SetAt' : cannot convert parameter 2 from 'class CStroke *' to 'class CObject *' (new behavior; please see help) scribbleView.cpp C:\MSDEV\MFC\include\afxtempl.h(1561) : error C2664: 'struct __POSITION *CObList::AddHead(class CObject *)' : cannot convert parameter 1 from 'class CStroke *' to 'class CObject *' (new behavior; please see help) C:\MSDEV\MFC\include\afxtempl.h(1563) : error C2664: 'struct __POSITION *CObList::AddTail(class CObject *)' : cannot convert parameter 1 from 'class CStroke *' to 'class CObject *' (new behavior; please see help) C:\MSDEV\MFC\include\afxtempl.h(1587) : error C2664: 'SetAt' : cannot convert parameter 2 from 'class CStroke *' to 'class CObject *' (new behavior; please see help) scribble.cpp C:\MSDEV\MFC\include\afxtempl.h(1561) : error C2664: 'struct __POSITION *CObList::AddHead(class CObject *)' : cannot convert parameter 1 from 'class CStroke *' to 'class CObject *' (new behavior; please see help) C:\MSDEV\MFC\include\afxtempl.h(1563) : error C2664: 'struct __POSITION *CObList::AddTail(class CObject *)' : cannot convert parameter 1 from 'class CStroke *' to 'class CObject *' (new behavior; please see help) C:\MSDEV\MFC\include\afxtempl.h(1587) : error C2664: 'SetAt' : cannot convert parameter 2 from 'class CStroke *' to 'class CObject *' (new behavior; please see help) Generating Code... Error executing cl.exe. Creating browse info file... scribble.exe - 9 error(s), 0 warning(s) The error refer to the declaration of template calss CTyped PtrList (I didn't modify this) // CTypedPtrList<BASE_CLASS, TYPE> template<class BASE_CLASS, class TYPE> class CTypedPtrList : public BASE_CLASS { public: // Construction CTypedPtrList(int nBlockSize = 10) : BASE_CLASS(nBlockSize) { } ................ POSITION AddHead(TYPE newElement) { return BASE_CLASS::AddHead(newElement); } POSITION AddTail(TYPE newElement) { return BASE_CLASS::AddTail(newElement); } ............... The example uses CTypedPtrList in a couple of places: In the interfacce file of class CScribbleDoc - class CScribbleDoc : public CDocument { protected: // create from serialization only void InitDocument(); CPen m_penCur; UINT m_nPenWidth; CScribbleDoc(); DECLARE_DYNCREATE(CScribbleDoc) // Attributes public: CStroke* NewStroke(); // Operations public: CTypedPtrList<CObList, CStroke*> m_strokeList; <----- CPen* GetCurrentPen() { return &m_penCur; } ........... } - and in implementation file of class CScribbleView (the view associated to document) void CScribbleView::OnDraw(CDC* pDC) { CScribbleDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here // The view delegates the drawing of individual strokes to // CStroke::DrawStroke( ). CTypedPtrList<CObList, CStroke*>& strokeList = <-------- pDoc->m_strokeList; POSITION pos = strokeList.GetHeadPosition( ); while (pos != NULL) { CStroke* pStroke = strokeList.GetNext(pos); pStroke->DrawStroke( pDC ); } } ........ Class CStroke is declared as follows: class CStroke : public CObject { public: CStroke( UINT nPenWidth ); protected: CStroke( ); DECLARE_SERIAL( CStroke ) // Attributes protected: UINT m_nPenWidth; // One width applies to entire stroke public: CArray<CPoint, CPoint> m_pointArray; // Series of connected // points // Operations public: BOOL DrawStroke( CDC* pDC ); public: virtual void Serialize( CArchive& ar ); }; I checked the artcles posted in books online\README for Microsoft Visual C++ 4.2/C/C++ LAnguage\... and I found a reference to the error I got as a more reobust implementation of type checking in "User Defined Conversion Selected by 'this' pointer type", but the examples posted there don't seem to be related to my situation... Can Anybody help me to understand the error and to eliminate it? Please help a novice programmer!!!! Thanks Angelo
T.R | Title | User | Personal Name | Date | Lines |
---|---|---|---|---|---|
1098.1 | completed solution is available online | XSTACY::imladris.ilo.dec.com::grainne | Grainne Ni Choiligh | Wed Mar 26 1997 05:35 | 16 |
The completed solution is available online, on the Visual C++ CD, and it builds correctly. If you look at the \SAMPLES directory on the VC++ CD, the completed Scrible application is in \SAMPLES\MFC\TUTORIAL\SCRIBBLE\STEPn (n = 1 to 8, corresponding to various additions to the basic scribble functionality.) According to the VC++ online docs, the end of the Scribble online tutorial (when you've added context-sensitive help) corresponds to Step 6 of the supplied Scribble samples. You could use the WinDiff utility to compare the contents of your project directory with the \SAMPLES\MFC\TUTORIAL\SCRIBBLE\STEP6 project directory. |