I wrote a class in vs2008. I am creating a new project and I need to incoporate that class into it. How do I do that. I added the .h to the header section and the .cpp to the source file. In the new program i did #include "firstclass" but that did not work.

What is the name of the header file? If it's firstclass.h, you need #include "firstclass.h"

You need only to include the header file and then create an instance of that class. If your class is called Foo, you would do:

Foo myClass;

myClass.(all the members should now be present) = blah;

this is the error I am getting:

Error 1 fatal error C1083: Cannot open include file: 'Queen.h': No such file or directory c:\Documents and Settings\jmartinez\My Documents\Visual Studio 2008\Projects\queen2\queen2\main.cpp 1 queen2

here is the main function of the new project:

#include "Queen.h"

void main()
{
    Queen * lastQueen =0;

    for (int i = 0; i <= 8; i++)
    {
        lastQueen = new Queen(i, lastQueen);
        if (!lastQueen -> findSoulution())
            cout << "no soultion\n";
    }

    lastQueen -> print();
}

Queen.h and Queen.cpp are included in the project. the .h in the header section the .cpp in the source section.

I was trying to find an example of setting up a project for multiple source files in MSVC, ones that I'd posted a while back. I found this, this, and this, but it seems that my previously posted links to screenshots now show up only as thumbnails. I think one of them might have used this image, but I forget.

The upshot at one time was to give a better picture of the relationship of a class header file, class source, and another source file. YMMV.

Queen.h and Queen.cpp are included in the project. the .h in the header section the .cpp in the source section.

Where is the Queen.h file in your file system? Is it in the same directory as main.cpp?

I was reading your previos post. I did not add the lines

#ifndef filename_h
#define filename_h
#endif

to any of the files how does that work. I think that is the problem.

can u please elaborate on using these commands.

Although you should be doing that, I don't think it's your problem. Your problem is that it doesn't know where to find Queen.h.

They are very simple to use, use #ifndef filename_h and #define filename_h before any code, and then #endif at the very end of the file. It helps to protect against repeated inclusions.

But I agree that this is not your problem, just a good coding standard to use.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.