Force to reimplement a static function in inherit classes

Posted by pacopepe on Stack Overflow See other posts from Stack Overflow or by pacopepe
Published on 2010-04-25T12:54:43Z Indexed on 2010/04/25 13:03 UTC
Read the original article Hit count: 147

Filed under:

Hi,

I have a program in C++ with plugins (dynamic libs). In the main program, I want to execute a static function to check if i can create a object of this type.

An example without dynamic libs (aren't neccesary to understand the problem):

#include "libs/parent.h"
#include "libs/one.h"
#include "libs/two.h"

int main(int argc, char * argv[])
{
    Parent obj;

    if (One.match(argv[1])) {
        obj = new One();
    else if (Two.match(argv[1])) {
        obj = new Two();
}

Now, i have a interface class named Parent. All plugins inherit from this class. Ideally, I have a virtual static function in Parent named match, and all the plugins need to reimplement this function.

The problem with this code is that i can't do a static virtual function in C++, so i don't know how to solve the problem.

Sorry for mi english, i did my best

© Stack Overflow or respective owner

Related posts about c++