1

Is it possible to make some cpp classes as a dll file so that I can import this dll and use these classes?
For example, I have four files like this:

// A.h
class A
{
public:
virtual void fun();
};
//A.cpp
void A::fun()
{
// do something
}
//B.h
class B : public A
{
public:
virtual void fun();
};
//B.cpp
void B::fun()
{
// do something
}

Now, what I want to do is to generate a dll file with these four files above. Then if I have another project, I just import the dll file and use the A and the B immediately, such as A a; a.fun(); B b; b.fun();

Yves
  • 11,597
  • 17
  • 83
  • 180
  • 1
    Exposing c++ classes through dll is not very good idea. User of your dll will need to use the same C++ standard libraries (in practice, the same compiler/IDE). – Anton Malyshev Aug 06 '15 at 10:13
  • @AntonMalyshev hmm, you are right. In fact, here is the reason why I want to use dll like this: I have a series of classes `Exception` (about 20 classes), which inherit the same class. It's kind of like a library of exception. I want to use them for each of my cpp projects. So I am considering that making them as a dll file may be a good idea. If not, can you tell me a better way to avoid copying these 20 classes each time? – Yves Aug 06 '15 at 10:44
  • simply include it from common directory (as source code)? – Anton Malyshev Aug 06 '15 at 10:55
  • @AntonMalyshev hmm... you mean I put them in the common directory? That's sounds nice. There is only one question left: where is the common directory?(I use vs2013) sry... I am fresh. – Yves Aug 06 '15 at 11:03
  • anywhere on the filesystem... you can add .cpp files to the project ("Add -> Existing Item") and to use .h files - add the directory to "Configuration Properties -> C/C++ -> General -> Additional Include Directories" for your project – Anton Malyshev Aug 06 '15 at 11:44
  • @AntonMalyshev OK. Thanks. – Yves Aug 06 '15 at 12:02

0 Answers0