Well I'm trying to do a little test class to work with vectors holding pointers to objects, but keep running into a problem with the compiler telling me I have undeclared identifiers. Now I'm took Java 1&2 and my school, and now have to take C++ 3 to graduate (Java 1 & 2 worked as pre-reqs). Its probably something super simple, but I just can't figure it out.
I'm using Visual Studio 2008.
vectorPointer.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
#include <string>
#include <vector>
#include "testBed.h"
using namespace std;
int main()
{
vector<testBed*> test;
for (int count = 0; count < 5; count++)
{
testBed test1;
testBed *testPtr;
testPtr = &test1;
testPtr->setInfo(count, count+1, count+2, count+3);
test.push_back(testPtr);
}
for (int count = 0; count < 5; count++)
{
test[count]->print();
}
}
|
testBed.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#ifndef TESTBED_H
#define TESTBED_H
#include <iostream>
#include <string>
using namespace std;
class testBed
{
private:
int int1;
int int2;
int int3;
int int4;
public:
testBed();
void setInfo(int int1, int int2, int int3, int int4);
void print();
};
#endif
|
testBed.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include "testBed.h"
testBed::testBed()
{
int1 = 0;
int2 = 0;
int3 = 0;
int4 = 0;
}
void setInf(int intA, int intB, int intC, int intD)
{
int1 = intA;
int2 = intB;
int3 = intC;
int4 = intD;
}
void print()
{
cout << int1 << " " << int2 << " " << int3 << " " << int4 << endl << endl;
}
|
Errors:
1>------ Build started: Project: Test 2, Configuration: Debug Win32 ------
1>Compiling...
1>testBed.cpp
1>c:\users\colby\desktop\test\test 3\testbed.cpp(13) : error C2065: 'int1' : undeclared identifier
1>c:\users\colby\desktop\test\test 3\testbed.cpp(14) : error C2065: 'int2' : undeclared identifier
1>c:\users\colby\desktop\test\test 3\testbed.cpp(15) : error C2065: 'int3' : undeclared identifier
1>c:\users\colby\desktop\test\test 3\testbed.cpp(16) : error C2065: 'int4' : undeclared identifier
1>c:\users\colby\desktop\test\test 3\testbed.cpp(21) : error C2065: 'int1' : undeclared identifier
1>c:\users\colby\desktop\test\test 3\testbed.cpp(21) : error C2065: 'int2' : undeclared identifier
1>c:\users\colby\desktop\test\test 3\testbed.cpp(21) : error C2065: 'int3' : undeclared identifier
1>c:\users\colby\desktop\test\test 3\testbed.cpp(21) : error C2065: 'int4' : undeclared identifier
1>vectorPointer.cpp
1>Generating Code...
1>Build log was saved at "file://c:\Users\Colby\Desktop\Test 2\Test 2\Debug\BuildLog.htm"
1>Test 2 - 8 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========