Thread: C++ modulazation

  1. #1
    Registered User
    Join Date
    Jul 2011

    Question C++ modulazation

    Hello all!
    I've come to a point where I want to have code that can be easily patched and replaced. (the program should load the file in the same directory as it, then use the code inside the file! Which is what modulization means to me, sorry if I used the wrong word).
    Now I've been searching for a way to do this for a while now...
    An example would be a Dynamic Link Library (.dll). But it doesn't entirely suit me - it requires a complete declaration of the class I want to use ahead. Including attributes and methods.

    So here I am wondering if this is even possible, and if so how.

    Here is an example of what I would like to do:

    //inside linked file - header
    class testClass
    int i;
    testClass(int newI); //set i
    int getInt(); //gets current value of I
    }; //testClass
    //inside linked file - source
    testClass::testClass(int newI)
    i = newI;
    int testClass::getInt()
    return i;
    //inside application - header
    //Code to load code from linked file
    load class testClass;
    //inside application - source
    #include "header.h"
    int main()
    testClass me(2)
    cout << me.getInt() << endl;
    return 0;

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Perhaps I'm too tied in to what your code is to see what you want it to be, as what you have typed seems like something that work as it is (EDIT: Assuming you turn "load class testClass" into the more syntactical "#include "testClass.h""). Do you want to be able to "get rid of" the header file, i.e., just have some sort of bare-bones interface and let the library details be hidden? In that case, you should research the pimpl idiom/opaque pointers.

Popular pages Recent additions subscribe to a feed

Tags for this Thread