|
-
April 14th, 2005, 04:44 PM
#1
pure virtual functions in a DLL
ok... first, let me say that I was playing with pure virtual functions, and got it to work all in one app. This is how I did, it really:
in TheClass.h (example):
Code:
class CMyClass
{
public:
CMyClass();
virtual void Initialize() = 0;
};
in TheClass.cpp:
Code:
#include "TheClass.h"
CMyClass::CMyClass()
{
Initialize();
}
in Main.cpp:
Code:
#include "TheClass.h"
class MyClass2 : public CMyClass
{
public:
void Initialize()
{
cout << "YAY!" << endl;
}
}
int main()
{
MyClass2 Blah;
//some random code
return 0;
}
That worked all in one app, just fine. So, while expirementing with it, I figured it'd be useful if I could put TheClass.h and TheClass.cpp into a DLL. The compiling worked great, but then linking came, and it said along the lines of:
error LNK2019: unresolved external symbol "public: virtual void __thiscall CMyClass::Initialize(void)"referenced in function "public: __thiscall CMyClass::CMyClass(void)"
So, my question is, is there any way that I can seperate it into a DLL like that? I tried taking off the "= 0" and doing just a "{ cout << "ok" << endl; }" thing, and that worked great, but then the new function created in the app was never called.
I guess it's fine if it can't be done, but I figured I'd see if someone knows a way anyway... I guess I'm just figuring mabye it's possible, and then I can make use of it. 
Thanks!
-
April 14th, 2005, 05:18 PM
#2
Re: pure virtual functions in a DLL
Ok, someone just gave me a tip that it doesn't work when in the constructor and destructor... with some playing around, I found that my problem was exactly that. Looking back over the code I had used previously, I now recall I didn't use a constructor or destructor, but that didn't really phase me until someone brought up to me that it couldn't be done that way.
Sorry.
-
April 14th, 2005, 05:48 PM
#3
Re: pure virtual functions in a DLL
 Originally Posted by crazycheetah
guess it's fine if it can't be done, but I figured I'd see if someone knows a way anyway... I guess I'm just figuring mabye it's possible, and then I can make use of it. 
Well... what would be the point of having a pure virtual function in a DLL? A DLL is meant to provide an implementation - code which can be linked at run time and executed. The whole point about a pure virtual function, in contrast, is that it has no implementation - it represents just an interface for an implementation to be provided elsewhere. So a "pure virtual function in a DLL" is just something that doesn't make any sense.
-
April 14th, 2005, 07:50 PM
#4
Re: pure virtual functions in a DLL
If you want to create CMyCalss in your app you should exprot CMyClass from dll.
There is another way just like COM's methord.
endless song
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|