Application container in C++

Dear All,

I need to design application container in C++. So looking for some suggestions.

Example:
Let say I create one class.

class test {

public init()
{
cout << "Hello"
}

}

I can compile above class and make libtest.so

Now I want to write one generic application to whom I can pass one argument (class name) and It should be able to invoke init method of that class.

Thanks
James.

Mmm, that looks/sounds very Java-esq.

You wouldn't normally expect to create a shared lib for something so small.

Typically, you'll produce a header file and maybe a source file.

The maybe part? A container ought to hold anything in a reasonably typesafe way, so that ususally implies the use of templates. If all your code is template code, you'll probably write it all in the header file.
Mmm, that looks/sounds very Java-esq.
[James]: Yes that is correct. I want to control life-cycle of application and want to manage other things in my way leaving only business logic to developer.

You wouldn't normally expect to create a shared lib for something so small.
[James]: It is just for example.

Typically, you'll produce a header file and maybe a source file.
[James]: If I produce header file for class, then I need to know all class name in advance. However I can define some abstract classes from which other classes can be derived. Even with templates also, I'm not getting some good design to proceed with.
If you have some idea.. pls do share.

Thanks
James.
Well, there is no built-in reflection system in C++, which means that you cannot call a function (or class method) only knowing the name of that function without additional effort. This means that unlike, e.g., C#, you cannot write a program like this one:

1
2
3
4
5
6
7
8
9
10
void f();
void g();
/* ... */

void main()
{
   std::string methodName;
   std::cin >> methodName;
   // Now you have the method name in your variable but you cannot use it to call a function  
}


This is due to the whole compilation-linking process where method names as well as all other symbolic information is dropped. This allows the compiler to perform various optimizations (e.g. inlining function calls).

Anyway, my first question would be - are you sure you want to use C++ for your task? Perhaps you'd be better off with built-in reflection mechanisms?

If you want to stick with C++, then you should think about the distribution of work between you and the people who will provide the "business logic". I.e. can you make your code a library that then will be used by the third party? Or perhaps, you will make a closed-source application that will be able to be extended with some sort of plugin system? This might be a good starting point for plugins: http://www.drdobbs.com/cpp/building-your-own-plugin-framework-part/204202899

Again, I'm not very experienced with other languages, but I'm pretty sure that implementing a flexible and extensible plugin architecture will be easier with Java or C# than with C++. I might be wrong here, but this is my gut feeling.

Anyway, your question seems too general to be answered without you providing more details. And even if you provide them there might not be a single "correct" answer.

Hope this helps at least a little bit :)
Topic archived. No new replies allowed.