Skip to main content
GameDev.net gamedev.net
🔒 Locked

Objects Placed in Separate Files

Started by WheelsRCool Aug 6, 2006 at 9:38 PM 11 replies 1.9k views
Original Post
WheelsRCool
WheelsRCool
Hey all, in a simulation program I was writing from the text I am learning from, it says to save the two objects of the program in separate header files on the C drive and use preprocessor directives to connect to them in the program. The program itself is a multi-object gas pump simulation. The program itself consists of the main() function and then the two objects, one the Pump object, the other the Customer object, are linked to in preprocessor directives. Each of these objects it said to save in the C drive and then link to. So for example, it said to name the Pump object "PUMP.H" and then to link to it like this: The Customer object was linked to as . I went into the "My Computer" section, went into the C:\ drive, created a folder named CLASSES. I am using Microsoft Visual Studio.NET 2003 for this, and I created each object as a New file, in which I named the Pump object PUMP.H and the area on the bottom detailing where it is saved said C:\ . But when I compile the program, it says it cannot access these two objects. I cannot figure out what I am doing wrong. For the record, this text is a bit old, maybe it shouldn't be saved as ".H"? Thanks, ---Wheels---
deathkrush
deathkrush
How are you using the preprocessor directives?

#include

or

#include

or

#include "PUMP.H"

?

Can you post some source code, it's really hard to tell what the problem is.
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
Deyja
Deyja
Quote:
maybe it shouldn't be saved as ".H"?


The only extension your IDE pays attention to is .cpp.

Quote:
OMFG. No. Stick all the files in the same directory, then include them with a relative path. "customer.h", not What you did is just gross.

Of course; an explanation of why it didn't work...

When the preprocessor finds an include encased in <>, it looks for that file in the standard include directories set up with the compiler. So, it was looking for 'C:\program files\msvc7\vc\include\C:\CLASSES\CUSTOMER.H'. Well. We can surely see the problem here, yes?
nife
nife
Quote:
Original post by Deyja
When the preprocessor finds an include encased in <>, it looks for that file in the standard include directories set up with the compiler. So, it was looking for 'C:\program files\msvc7\vc\include\C:\CLASSES\CUSTOMER.H'. Well. We can surely see the problem here, yes?


In short: the OP needs to type #include "C:/CLASSES/CUSTOMER.H" instead of <>.
Killers don't end up in jailThey end up on a high-score!
WheelsRCool
WheelsRCool
Deyja, I think I see what the problem is, but remember I'm a complete newb to C++, and this book is a bit old, and also not all of the author's code in the book is bug-free, so...ANYHOW, I will try what you guys suggested; if it still doesn't work, I will post the source code to the program.

And it was the author's code that was so bad, I don't know why he wrote bad code into the text.

Thanks,
---Wheels---
starfleetrp
starfleetrp
Well if it is really that bad try to getting new book because if he screwed that up well you'll probably be learning bd habits and encouter tons of bugs.
WheelsRCool
WheelsRCool
Yeah, true

Anyways, it didn't work, but I have a feeling it is more me then you guys, b/c I don't know squat right now, anyhow, here is the code to the program's main() function, copied exactly from the book:

#include
#include
#include // note full use of path name here
#include // again - a full path name is used

const float SIMTIME = .5; // simulation time in hours
const int MINUTES = 60; // number of minutes in an hour
const float AMT_IN_TANK = 300; // initial gallons in the tank
const float TODAYS_PRICE = 1.25; // price-per-gallon

int main()
{
Pump a(AMT_IN_TANK, TODAYS_PRICE); // declare 1 object of type Pump
Customer b; // declare 1 object of type Customer
int totalTime = 0;
int idleTime;
int amtRequest;
int simMinutes; // simulation time in minutes

simMinutes = SIMTIME * MINUTES;
cout << "\nStarting a new simulation - simulation time is "
<< simMinutes << " minutes" << endl;
a.values();

// get the first arrival
idleTime = b.arrive();
totalTime += idleTime;

while(totalTime <= SimMinutes)
{
cout << "\nThe idle time is " << idleTime << " minutes" << endl
<< " and we are " << totalTime
<< " minutes into the simulation." << endl;
amtRequest = b.gallons();
a.request(float(amtRequest));

// get the next arrival
idleTime = b.arrive();
totalTime += idleTime;
}

cout << "\nThe idle time is " << idleTime << " minutes." << endl
<< "As the total time now exceeds the simulation time, " << endl
<< " this simulation run is now over." << endl;

return 0;
}

Okay, obviously there's the Pump class and the Customer class, which the program makes calls to for computing, but I stored those files by making a folder named CLASSES in the C drive and then saving the folders named PUMP.H and CUSTOMER.H in the CLASSES folder. The folders themselves are literally named PUMP.H and CUSTOMER.H and their source files are named things like PUMP.H.cpp and CUSTOMER.H.cpp.

The above code is how they were linked to in the text, but according to the compiler, it says, "No such file or directory." I got this when using the pointy brackets (<,>) and when using quotes instead.
Palidine
Palidine
Is this actually where the files live on your machine? i.e. if you type it in an explorer window does it go to where your cpp files and headers are?

C:\CLASSES

And please, listen to deyja and NEVER use absolute paths.

If random.cpp and random.h are in the same folder you can just do this:

random.cpp:
#include "random.h"//the contents of random.cpp


there's a great article on putting classes in different files in the articles & resources section. read it.

-me

[

EDIT: oh, the problem i believe is that you're using angle brackets and not double quotes to do you #includes it should look like:

#include "C:/classes/whatever.h"

]
WheelsRCool
WheelsRCool
I will read it, definitely, thanks for the link, BUT, I did use double quotes, and it didn't work. Also, there is no "PUMP.H" file and "PUMP.cpp" file. There is a main folder named "PUMP.H" and contained in that folder are things like "PUMP.H.cpp," so the .H was probably pointless.

I won't post any more questions 'till after I read the link though.

Thanks,
---Wheels---
Deyja
Deyja
I tell ya what - Take a screen shot of the directory structure in explore's tree view, and send it off to TheDailyWTF.com
Zahlman
Zahlman
Quote:
Original post by Deyja
I tell ya what - Take a screen shot of the directory structure in explore's tree view, and send it off to TheDailyWTF.com


Nonono. First he should print out the screen shot, put it on a wooden table, photograph it, scan in the photo and send in the scan :D
WheelsRCool
WheelsRCool
Well, I must say, at least I have one thing going for me with this article: it says that this topic usually confuses the daylights out of newbs.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.