• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

Code won't compile

I wrote this code in Microsoft Visual C++ 6, I can not find any reasion for why it will to Compile.  

The primary error message occures because the CDVTestDoc class in "CDVTestDoc* pDoc = (CDVTestDoc*)GetDocument();" is undeclared, yet ITS THERE!

Heres the Source;
      CDVTestDoc* pDoc = (CDVTestDoc*)GetDocument();
      ASSERT_VALID( pDoc );
      CString      szName;
      m_edNames.SetWindowText( szName );
      m_edNames.SetWindowText( "" );
      if( szNames.GetLength() > 0 )
            int nIndex = pDoc->AddName( szName );
            m_lbNames.InsertString( nIndex, szName );
            m_lbNames.SetCurSel( nIndex );

Here are the error messages;
C:\vc\Source Library\DVTest\FormText.cpp(68) : error C2065: 'CDVTestDoc' : undeclared identifier
C:\vc\Source Library\DVTest\FormText.cpp(68) : error C2065: 'pDoc' : undeclared identifier
C:\vc\Source Library\DVTest\FormText.cpp(68) : error C2059: syntax error : ')'
C:\vc\Source Library\DVTest\FormText.cpp(74) : error C2065: 'szNames' : undeclared identifier
C:\vc\Source Library\DVTest\FormText.cpp(74) : error C2228: left of '.GetLength' must have class/struct/union type
C:\vc\Source Library\DVTest\FormText.cpp(76) : error C2227: left of '->AddName' must point to class/struct/union
Error executing cl.exe.

DVTest.exe - 6 error(s), 0 warning(s)
1 Solution
Can you post the code that comes before that?

Are you sure that CDVTestDoc is defined by that point in the source?  Is it defined in an include file?  Is that include file included?  If you place a syntax error in the include file at the location where CDVTestDoc is defined, does the compiler report an error?
#include "{the header file that contains the definition for CDVTestDoc}"

darnison062499Author Commented:
Thanks, I didn't know I had to include the header file every time I call an external class.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now