how do i include pre-existing classes.

Hi guys,

I'm using the C++ Primer 5th Edition to learn C++ and I'm stuck on a problem involving classes.

At this point I haven't learned how to create my own classes yet and I am supposed to download the Sales_item class and use it to write my program.

I have it downloaded but I do not know where to put it to make it work. I'm using Microsoft Visual Studios Express 2012.

I tried adding the Sales_item.h header, but it says it cannot open source file for Sales_item.h. Where do I put all the other stuff that comes with the class?

Thank you for your help.
Last edited on
Make sure that the directory in which you include your file is the correct one. If it says it cannot open the source of header files, it is most likely because it cannot find it.
That's what I'm trying to ask. Which directory am I suppose to put it into? Do I just put everything inside the project folder?

E:\Documents\Visual Studio 2012\Projects\PrimerProjects\Primer1.20\

do i put it in there? or deeper?
Last edited on
Oh, i really wish books wouldn't ask you to use something before they've given you the knowledge of what it is you're using.

Put it in the same folder as the rest of your source files for that project. The directory you mentioned looks accurate.
Then just add an existing file to the project from inside Visual Studio.
Last edited on
Thank You! I found main.cpp source file and put everything with it and now it works.
I just looked over those files that I downloaded and most of them are the answer key to the previous problems. I thought everything was linked to the Sales_item.h. I was like "wtf, you need all this to make a class?" lol
Kevin145, remember that at 'some' point, you'll want to keep all of those "Types" of files separate - usually in their own files;
OBJ, BIN, CPP, EXE, H, -should all be kept in their own folders - and then have your IDE ( VS2013?) point to them ( or sometimes your code will point to them). Getting 100-200 ( or 500-800) files all in one folder, most with nearly the exact same name gets to be a real headache real fast.
Last edited on
Topic archived. No new replies allowed.