Thread: error C2065 undeclared identifier

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    98

    error C2065 undeclared identifier

    i am getting an error with this file, i think it has something to do with .cph files, have to modify one of them, but donot know how. here is the code and the error messages. oh, i am using msv c++ 6.0, and have downloaded and installed the service packs.

    // EX04CView.cpp : implementation of the CEX04CView class
    //

    #include "stdafx.h"
    #include "EX04C.h"

    #include "EX04CDoc.h"
    #include "EX04CView.h"

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif

    /////////////////////////////////////////////////////////////////////////////
    // CEX04CView

    IMPLEMENT_DYNCREATE(CEX04CView, CScrollView)

    BEGIN_MESSAGE_MAP(CEX04CView, CScrollView)
    //{{AFX_MSG_MAP(CEX04CView)
    ON_WM_KEYDOWN()
    ON_WM_LBUTTONDOWN()
    //}}AFX_MSG_MAP
    // Standard printing commands
    ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // CEX04CView construction/destruction

    CEX04CView::CEX04CView() : m_rectEllipse(0, 0, 4000, -4000)
    {
    m_nColor = GRAY_BRUSH; // TODO: add construction code here

    }

    void CEX04CView::OnDraw(CDC* pDC)
    {
    pDC->SelectStockObject(m_nColor);
    pDC->Ellipse(m_rectEllipse);
    // TODO: add draw code for native data here
    }

    void CEX04CView::OnInitialUpdate()
    {
    CScrollView::OnInitialUpdate();
    CSize sizeTotal(20000, 30000); //20 by 30 cm
    CSize sizePage(sizeTotal.cx / 2, sizeTotal.cy / 2);
    CSize sizeLine(sizeTotal.cx / 50, sizeTotal.cy / 50);
    SetScrollSizes(MM_HIMETRIC, sizeTotal, sizePage, sizeLine);

    }

    /////////////////////////////////////////////////////////////////////////////
    // CEX04CView printing

    BOOL CEX04CView::OnPreparePrinting(CPrintInfo* pInfo)
    {
    // default preparation
    return DoPreparePrinting(pInfo);
    }

    void CEX04CView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    // TODO: add extra initialization before printing
    }

    void CEX04CView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    // TODO: add cleanup after printing
    }

    /////////////////////////////////////////////////////////////////////////////
    // CEX04CView diagnostics

    #ifdef _DEBUG
    void CEX04CView::AssertValid() const
    {
    CScrollView::AssertValid();
    }

    void CEX04CView:ump(CDumpContext& dc) const
    {
    CScrollView:ump(dc);
    }

    CEX04CDoc* CEX04CView::GetDocument() // non-debug version is inline
    {
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEX04CDoc)));
    return (CEX04CDoc*)m_pDocument;
    }
    #endif //_DEBUG

    /////////////////////////////////////////////////////////////////////////////
    // CEX04CView message handlers

    void CEX04CView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    switch (nChar) { // TODO: Add your message handler code here and/or call default
    case VK_HOME:
    OnVScroll(SB_TOP, 0, NULL);
    OnHScroll(SB_LEFT, 0, NULL);
    break;
    case VK_END:
    OnVScroll(SB_BOTTOM, 0, NULL);
    OnHScroll(SB_RIGHT, 0, NULL);
    break;
    case VK_UP:
    OnVScroll(SB_LINEUP, 0, NULL);
    break;
    case VK_DOWN:
    OnVScroll(SB_LINEDOWN, 0, NULL);
    break;
    case VK_PRIOR:
    OnVScroll(SB_PAGEUP, 0, NULL);
    break;
    case VK_NEXT:
    OnVScroll(SB_PAGEDOWN, 0, NULL);
    break;
    case VK_LEFT:
    OnHScroll(SB_LINELEFT, 0, NULL);
    break;
    case VK_RIGHT:
    OnHScroll(SB_LINERIGHT, 0, NULL);
    break;
    default:
    break;
    }
    }

    void CEX04CView::OnLButtonDown(UINT nFlags, CPoint point)
    {
    CClientDC dc(this);
    OnPrepareDC(&dc);
    CRect rectDevice = m_rectEllispe;
    dc.LPtoDP(rectDevice);
    if (rectDevice.PtInRect(point)) {
    if (m_nColor == GRAY_BRUSH){
    m_nColor = WHITE_BRUSH;
    }
    else {
    m_nColor = GRAY_BRUSH;
    }
    InvalidateRect(rectDevice);
    }
    }


    heres the error codes

    c:\ex04c\ex04cview.cpp(139) : error C2065: 'm_rectEllispe' : undeclared identifier
    c:\ex04c\ex04cview.cpp(139) : error C2440: 'initializing' : cannot convert from 'int' to 'class CRect'
    No constructor could take the source type, or constructor overload resolution was ambiguous
    MainFrm.cpp
    Generating Code...
    Error executing cl.exe.

    EX04C.exe - 2 error(s), 0 warning(s)

  2. #2
    Registered User Liam Battle's Avatar
    Join Date
    Jan 2002
    Posts
    114
    here is the MSDN info for that error code: (long read)

    'identifier' : undeclared identifier

    The specified identifier was not declared.

    A variable’s type must be specified in a declaration before it can be used. The parameters that a function uses must be specified in a declaration, or prototype, before the function can be used.

    Tips

    Make sure any include file containing the required declaration is not omitted.


    Make sure you are including any necessary header files if you have defined VC_EXTRALEAN, WIN32_LEAN_AND_MEAN, or WIN32_EXTRA_LEAN. Defining these symbols excludes some functionality (certain header files are excluded) from windows.h and afxv_w32.h (for MFC applications) to speed compiles. Search windows.h and afxv_w32.h for these symbols for the most up-to-date description of what is excluded.


    Make sure the identifier name is spelled correctly.


    Make sure the identifier is using the correct upper- and lowercase letters.


    Make sure all string constants have closing quotes.


    This error can be caused by having a newline character in a string constant without a continuation character. For example:
    #include <stdio.h>
    main() {
    printf("\n %s
    %s // error: 's' : undeclared identifier
    %s",
    "this", "is", "it");
    }

    Special considerations must be taken when splitting a constant string over several lines. The most common method is to change the format string. Strings separated only by whitespace (spaces, tabs, newlines) are concatenated. For example:
    #include <stdio.h>
    main() {
    printf("\n %s"
    " %s"
    " %s",
    "this", "is", "it");
    }

    An older, less-preferred method is to use line continuation by typing a backslash at the end of a line. For example:
    printf("\n %s\
    %s\
    %s",
    "this", "is", "it");

    This method is not often used because the spaces at the beginning of each continued line become part of the string.

    Make sure you're using proper namespace scope. For example, in order to properly resolve ANSI C++ Standard Library functions and operators, you must state that you're using the std namespace with the using directive.
    For example, unless the using directive is uncommented, the following sample will fail to compile because the cout stream is defined in the std namespace:

    #include <iostream>
    // using namespace std;
    void main()
    {
    cout << "Hello" << endl;
    }

    ----------------------
    here is the second error code info:

    'conversion' : cannot convert from 'type1' to 'type2'

    The compiler was unable to cast from ‘type1’ to ‘type2.’ If you’ve encountered this error on code which compiled with an earlier version of Visual C++, please read Technote: Improved Conformance to ANSI C++ for more information.

    The following example illustrates this error.

    void main()
    {


    int *i;
    float j;

    j = (float)i; /* cannot cast from
    pointer to int to float */


    }

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    I still can't believe that MSDN uses void main in it's examples.

    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    >I still can't believe that MSDN uses void main in it's examples.

    LOL! that's microsoft for ya

  5. #5
    Señor Member
    Join Date
    Jan 2002
    Posts
    560
    Why is void main such a big deal?

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Why is void main such a big deal?
    Because it's wrong. Using void main makes your program completely undefined, it could do anything from work properly to launch nuclear missiles and destroy the human race through thermonuclear war (assuming you have that hardware option installed).

    -Prelude
    My best code is written with the delete key.

  7. #7
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >Why is void main such a big deal?

    Your program runs in an environment, this environment has called the program and expects a return value. If you declare main as void, the return value is undefined. So the environment doesn't know how the program has finished.

    Prelude's examples are little bit extreme, but the point is that the environment has to make assumptions. It can assume that everything is done well, i.e. the program has finished without problems, so a next program is started with the assumption that everything is OK.

    This is also the reason why I think that functions should always send back a return value, or at least should pass a variable which indicates how the function has finished. It's one of the basic rules of safe and robust programming.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM