CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Undeclared identifier..

  1. #1
    Join Date
    Nov 2008
    Posts
    2

    Undeclared identifier..

    That's right, I said it. Please don't call me an idiot, but I actually need help with this. My code follows, and it throws a C2065 every reference to i. This really doesn't even belong in this forum, but like I said I'm stumped. Thank you!

    driver.cpp:
    #include <iostream>
    #include "MyClass.h"
    using namespace std;

    int main() {
    MyClass list[3];
    int i;

    for(i=0; i<3; i++)
    list[i].setInt(i+1);
    for(i=0; i<3; i++)
    cout << list[i].getInt() << "\n";
    return 0;
    }

    MyClass.h:
    using namespace std;

    class MyClass {
    public:
    void setInt(int j);
    int getInt();
    private:
    int i;
    };

    MyClass.cpp:
    #include "MyClass.h"

    using namespace std;

    void setInt(int j) {
    i = j;
    }
    int getInt() {
    return i;
    }
    Last edited by TurkeyMaster77; November 3rd, 2008 at 09:13 AM.

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Undeclared identifier..

    It doesn't know what i is:
    Code:
    void setProperties(int j)
    {
        i = j; 
    }
    Did you mean:
    Code:
    void MyClass::setInt(int j)
    {
        i = j; 
    }
    - petter

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,588

    Re: Undeclared identifier..

    Please use code tags.

    i is defined in main(). It's not visible outside the function it's defined in.

  4. #4
    Join Date
    Nov 2008
    Posts
    2

    Re: Undeclared identifier..

    I'm really sorry to waste everybodies time here..

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,588

    Re: Undeclared identifier..

    Quote Originally Posted by TurkeyMaster77
    I'm really sorry to waste everybodies time here..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)