Ah, I understand what you are saying now. Let me explain how interfaces working in C++ first. The header file usually looks something like this:
Code:
class ISomeFace
{
public:
virtual ~ISomeFace();
virtual void SomeMethod() = 0;
};
The above class is an abstract class. Inside the game plugin itself, there would be a class like this:
Code:
class cSomeFace : public ISomeFace
{
public:
cSomeFace() { /* code */ }
virtual ~cSomeFace() { /* code */ }
virtual void SomeMethod() { /* code goes here */ }
};
Now, if you tried to create an instance of ISomeFace, you would get an error:
Code:
ISomeFace *pFace = new ISomeFace();
1) There isn't a constructor for the class. This is because it is abstract.
2) Abstract classes can not be initialized. They are simply a virtual table.
3) Inside your server plugin, you should define a function like this:
Code:
ISomeFace *CreateAFace()
{
cSomeFace *pFace = new cSomeFace(); // This is valid!
return (ISomeFace*) pFace;
}
Now, since the pointer returned is actually an object that over-rides the methods contained in ISomeFace, the virtual table will be able to determine the correct call of functions. For example, if another C++ program wanted to use your interface:
Code:
ISomeFace *pFace = InterfaceFactory->CreateAFace();
You might be asking, how do we get to this point without being able to initialize an interface? Well, if you have ever used a DLL export, then the process isn't too difficult to understand. Programs are able to export functions, I believe in SourceMod there is actually a macro in the sdk include file that helps you avoid this practice. GetSMAPI or something like that. Well, what I like doing is handing off a single instance of what I like to call an interface factory. The interface factory is the only thing that has to be exported/imported.
In sumation, interfaces are not initialized by the third party for a reason. They are only an abstract representation (AKA a virtual table)
Please let me know if this is hard to understand, I know I am not the best teacher.
__________________