ok so now i have split my program into a header file, a cpp, and the main cpp, and i have included the header file into my two cpp's. Everything was going well before I debugged it and I had all these errors saying that by object wasn't declared.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
//Color.cpp
#include "stdafx.h"
#include "Color.h"
#include <iostream>
using namespace std;
#include <string>
#include "time.h"
color::color(){
colors[0] = "Red"; colors[1] = "Orange"; colors[2] = "Yellow"; colors[3] = "Green";
colors[4] = "Blue"; colors[5] = "Indigo"; colors[6] = "Violet";
}
string color::getColor(){
srand(time(NULL));
int randomNum = rand() % 7;
return colors[randomNum];
}
void color::printArray(){
for (int i = 0; i < 7; i++){ cout << colors[i] << endl; }
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
//Color.h
#include "stdafx.h"
#include <iostream>
#include "stdafx.h"
using namespace std;
class color{
private:
string colors[7];
public:
color(void);
string getColor();
void printArray();
};
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// getColorAssignment3JasonRoss.cpp : Defines the entry point for the console application.
//
#include "Color.h"
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
color bo;
cout << bo.getColor() << endl << endl;
bo.printArray();
return 0;
}
|
Errors:
Error 4 error C2065: 'bo' : undeclared identifier 11
Error 5 error C2065: 'bo' : undeclared identifier 12
Error 7 error C2065: 'bo' : undeclared identifier
Error 2 error C2065: 'color' : undeclared identifier \getcolorassignment3jasonross.cpp 11
Error 3 error C2146: syntax error : missing ';' before identifier 'bo'
Error 6 error C2228: left of '.getColor' must have class/struct/union c:\users\jason\documents\visual studio 2013\projects\getcolorassignment3jasonross\getcolorassignment3jasonross\getcolorassignment3jasonross.cpp 12
Error 8 error C2228: left of '.printArray' must have class/struct/union c:\users
Warning 9 warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
Warning 1 warning C4627: '#include "Color.h"': skipped when looking for precompiled header use
Any ideas of what I did wrong?
Why would my #include "Color.h" be skipped?