Jeff Flinn said:
Provide a more concrete example of what your trying to accomplish, and I'm
sure you'll get much better response.
Ok, sorry about that. I want to make parser that needs to parse data into
different types of objects, both single objects and arrays (or vectors) of
objects. An "object" can thereby also be a single int value or a C++ string.
Basically I need to do something like this:
#include <iostream>
#include <vector>
using namespace std;
class A { };
class B : public A { };
template <typename T> void somefunc(T& data) { cout << "single template" <<
endl; }
void somefunc(A& data) { cout << "single A" << endl; }
template <typename T> void somefunc(vector<T>& data) { cout << "vector
template" << endl; }
void somefunc(vector<A>& data) { cout << "vector A" << endl; }
int main()
{
int test1;
A test2;
B test3;
vector<int> test4;
vector<A> test5;
vector<B> test6;
somefunc(test1);
somefunc(test2);
somefunc(test3);
somefunc(test4);
somefunc(test5);
somefunc(test6);
return 0;
}
Now, the output of this program is:
single template
single A
single template
vector template
vector A
vector template
This means for the class B, which is derived from A, the compiler calls the
template, but to accomplish what I want, I would need it to call the
overloaded function for class A for all objects, that are derived from A. As
you can imagine, I want to use the template for all build-in types & C++
Strings and the overloaded class A versions for the classes, I define
myself. Basically, I would need the output from the above program to be:
single template
single A
single A
vector template
vector A
vector A
Frank