C++ modulazation

This is a discussion on C++ modulazation within the C++ Programming forums, part of the General Programming Boards category; Hello all! I've come to a point where I want to have code that can be easily patched and replaced. ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    62

    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:

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

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21