-
November 3rd, 2008, 09:08 AM
#1
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.
-
November 3rd, 2008, 09:14 AM
#2
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
-
November 3rd, 2008, 09:16 AM
#3
Re: Undeclared identifier..
Please use code tags.
i is defined in main(). It's not visible outside the function it's defined in.
-
November 3rd, 2008, 09:19 AM
#4
Re: Undeclared identifier..
I'm really sorry to waste everybodies time here..
-
November 3rd, 2008, 09:35 AM
#5
Re: Undeclared identifier..
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|