Im working in visual studio.

In a regular win32 console app i've written a class i want to use in other projects.

Basically my question is what is the most efficient way to do this? (I just assumed it would be creating a header file)

What kind of project do i need to make? And how do i implement the class afterwards?

When I use classes in other files I use:

#include "filename.cpp"

I put this line in the file containing my main() function. This lets you use the class in your main() function.

When I use classes in other files I use:

#include "filename.cpp"

I put this line in the file containing my main() function. This lets you use the class in your main() function.

Sooner or later you'll need to learn that this is the wrong thing to do. Generally you want to put the interface (class definition, function prototypes, etc.) in the header, and put the implementation -- the active code (function definitions, etc.) in a source file. Templates throw a monkey wrench into this generalization, however.

Edited 7 Years Ago by Dave Sinkula: n/a

Sooner or later you'll need to learn that this is the wrong thing to do. QUOTE]
Can you please explain why this is wrong? It's the way I learned in school and works exactly as I want it to. Is it actually wrong or is it just not the industry standard? Thanks.

Oh, I've never tried including the class in more than one file that way. I wish my C++ teacher would have taught me the right way. ;)
Thanks, Dave.

This article has been dead for over six months. Start a new discussion instead.