I created a class 'Rectangle' under the header file 'Rectangle.h' as part of a build that I am doing. However, when I try and declare an object 'box' using that class it doesn't seem to recognize Rectangle as a class that I can make an object with. Also, the code for the header file and class function are in different files that are part of my build but I didn't include them here to prevent clutter. Any thoughts on why this is happening?
#include <cstdlib> // for rand function (random number generator)
#include <fstream> // for file input and output
#include <iostream> // for cin and cout
#include <iomanip> // for manipulators such as setw
#include <string> // for using string data types
#include <ctime> // for time() function
#include "Rectangle.h" // for rectangle function
#include "windows.h" // for cursor manip
usingnamespace std;
void placeCursor(HANDLE, int, int);
struct rectDim
{
double length;
double width;
};
void displayPrompts(HANDLE);
void getUserInput(HANDLE, rectDim&);
void displayData (HANDLE, rectDim);
int main()
{
{
// Program Main Menu
// Projects 1-8 preceded project 9 but are not icluded
cout <<"9) Project 9.0 - Rectangle Area" << endl;
switch (num) // switch to programs selected from main menu
{
case 9:
//initialize arrays
menuChoices[choices].optionNum = 9;
menuChoices[choices].optionNam = "Project 9.0 - Rectangle Area";
{
rectDim input;
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
displayPrompts(screen);
getUserInput(screen, input);
displayData (screen, input);
Rectangle box; // Declare a Rectangle object
//program header
cin.clear();
system("cls");
displayPrompts(screen);
getUserInput(screen, input);
{
// Call member functions to get box information to display
cin.clear();
system("cls");
displayData (screen, input);
}
system("cls");
break;//end switch and return to menu
}
I was about to upload my .h file here when I found out there is a conflict with a C++ library function that also has a variable named "Rectangle". I did not expect this. I've updated my files to 'RectangleShape.h' and 'RectangleShape.cpp' and that seems to have fixed the issue. Thank you all.