error with Static Library code

This is a discussion on error with Static Library code within the C++ Programming forums, part of the General Programming Boards category; hi all, i'm learning the book "Teach Yourself Visual C++ 6 in 21 days" , and i'm in Chapter 16 ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    4

    Question error with Static Library code

    hi all,
    i'm learning the book "Teach Yourself Visual C++ 6 in 21 days" , and i'm in Chapter 16 - Creating Your Own Classes and Modules . I did everything like it said but i've an error. This Static Library project has 2 classes , 1 class , called CLine , is added from other project and 1 class , called CModArt , is added in this project .
    So this is the code to creat new line in CModArt class :
    Code:
    void CModArt::NewLine()
    {
    	int lNumLines;
    	int lCurLine;
    	int nCurColor;
    	UINT nCurWidth;
    	CPoint pTo;
    	CPoint pFrom;
    
    	//Normalize the rectangle before determining the width and height
    	m_rDrawArea.NormalizeRect();
    	//Get the area width and height
    	int lWidth = m_rDrawArea.Width();
    	int lHeight = m_rDrawArea.Height();
    
    	//Determine number of parts to this squiggle
    	lNumLines = rand() % 100;
    	//Are there any part in squiggle
    	if (lNumLines > 0)
    	{
    		//Determine color
    		nCurColor = rand() % 8;
    		//Determine the pen width
    		nCurWidth = (rand() % 8) + 1;
    		//Determine the start point for the squiggle
    		pFrom.x = (rand() % lWidth) + m_rDrawArea.left;
    		pFrom.y = (rand() % lHeight) + m_rDrawArea.top;
    
    		//Loop through number of sequents
    		for (lCurLine=0; lCurLine<lNumLines; lCurLine++)
    		{
    			pTo.x = ((rand() % 20) - 10) + pFrom.x;
    			pTo.y = ((rand() % 20) - 10) + pFrom.y;
    
    			//Creat a new line
    			//CLine *pLine = new CLine(pFrom, pTo, nCurWidth, m_crColors[nCurColor]);
    			CLine *pLine = new CLine(pFrom, pTo, m_crColors[nCurColor]);
    
    			try
    			{
    				//try to add new line
    				m_oaLines.Add(pLine);
    			}
    
    			//Check did we run into memory exception
    			catch (CMemoryException *perr)
    			{
    				//Notice user the message
    				AfxMessageBox("Out of memory", MB_ICONSTOP | MB_OK);
    				//Did we creat a new line
    				if (pLine)
    				{
    					delete pLine;
    					pLine = NULL;
    				}
    				//Delete the exception
    				perr->Delete();
    			}
    			//Set the starting point to the end point;
    			pFrom = pTo;
    		}
    	}
    }
    and this is the error :
    ...\ModArt.cpp(82) : error C2065: 'CLine' : undeclared identifier
    and this is the 82 line :
    Code:
    CLine *pLine = new CLine(pFrom, pTo, m_crColors[nCurColor]);
    Thanx 4 all ur helps!

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > ...\ModArt.cpp(82) : error C2065: 'CLine' : undeclared identifier
    Do you have a header file for the CLine class? It sounds like you need to:
    Code:
    #include "cline.h"
    at the top of ModArt.cpp. Or if you don't have a header for CLine, I guess you'd have to include cline.cpp.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    4
    oh , i fixed this bug but i dont understand why . Because before that , I already have include "cline.h" in ModArt.cpp . But now when i also include "cline.h" in ModArt.h , it work gud?
    so wat prob here cus i think i just need to include "cline.h" in ModArt.cpp , no need in ModArt.h ?

    thanx 4 all ur helps!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Free.
    By chakra in forum C Programming
    Replies: 9
    Last Post: 12-15-2008, 11:20 AM
  2. Linking errors with static var
    By Elysia in forum C++ Programming
    Replies: 8
    Last Post: 10-27-2007, 06:24 PM
  3. C# and C++ static library integration?
    By gotclout in forum C# Programming
    Replies: 5
    Last Post: 06-07-2006, 07:10 AM
  4. [GLUT] Pointers to class methods
    By cboard_member in forum C++ Programming
    Replies: 13
    Last Post: 02-16-2006, 04:03 PM
  5. Accessing C++ library from C code
    By nipun in forum C Programming
    Replies: 1
    Last Post: 06-10-2004, 12:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21