help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dynamic module loading vs. using ancestor class functions


From: FEJES Jozsef
Subject: dynamic module loading vs. using ancestor class functions
Date: Fri, 21 Jan 2005 18:25:19 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041217

Hi!

(I've read c++ dlopen mini howto, didn't help)

There's a problem I can't solve about dynamic module loading with C++. Let's see a simple example. It'll be just a theoretical illustration. I have a simple socket interface (abstract class) with a constructor, init(), connect() and read(). There's a simple socketv4 class in the socketv4.so module that implements all functions. Now I want a socketv6 class in socketv6.so module, whose ancestor is socketv4. (I know it could be compiled together with socketv4, but it's just illustration. There are two different modules.) Four cases possible:

- connect(): Just override, reimplement the function, no problem.

- read(): I don't want to redefine it because it would be the same. What happens if I call socketv6::read()? socketv6.so doesn't contain the code of read(), it's in socketv4. How can that symbol be resolved? See the problem: what happens if socketv4 is not even loaded?

- init(): Suppose it's the mixture of the previous two: some part of it is the same, some is not, so I do this:
socketv6::init() {
  socketv4::init(); // call the original, overridden function
  // do some other stuff here
}
Same problem: how to find the code of socketv4::init()?

- constructor: Special case of the previous problem.When socketv6 is constructed, first socketv4's constructor is called, but how?

Hope you get the idea. Some bad ideas to solve my problem:

- There would be no questions if I reimplemented everything in socketv6, but that's too bad, it would lose it's meaning. It's a big project, I really need to reuse code.

- #include-ing the reused code parts sucks, too.

- Socketv6 has no ancestor, it creates a socketv4 instance internally, so it can call it's functions, but it's not good either, because it would use double memory and data structures. So it would be really hard to get it working this way.

Using the standard overriding, ancestor::overriddenfunction(), etc C++ way would be the best. But how? Please help!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]