I've been searching for a few days already and can't seem to find a proper answer to my question.
In my program, I need to have a first class (D) that reads a file and instanciate some basic objects, that will be used to create some others. Once they're created, I call a parsing function with a collection of objects PC, which are NECESSARILY of class or child of class P.
To do so, I've implemented a collection of PC, that is merely an encapsulation of a vector storing PC objects.
In D.h
class D {
/*...*/
template<typename PC>
parse(vector<string> cmdline, V<PC> vpcs);
}
In D.cpp
template<typename PC>
parse(vector<string> cmdline, V<PC> vpcs) {
/* parse options */
/* check with a functor if PC is really of class (child of) P */
vpcs.push_back( PC(args) );
}
In V.h
template<typename PC>
class V {
/*...*/
vector<PC> vpcs;
}
In main.cpp
{
D des;
vector<string> cmdline;
V<P*> vps;
des.parse(cmdline, vps);
}
Why do I want to do this? Because I'm writing a library and we have to let the future developers create their own child of P for specialized programs so I want to do something really generic (therefore : templated :)). I've already implemented and tested my function with class P, fully working, now I want to improve this. But I don't manage to compile my code or neither understand what I've been doing wrong.
(Also, for the record : first time using templates so I've read a lot of documentation but application is always a bit difficult!)
Thanks for your future answers and let me know if I can add more details!
EDIT : Okay, so the post given as "duplicate" (which I never read during my research, maybe not the correct keywords I typed in?) helped me for one thing but in fact it was not this problem at all. I had another one that I manage to resolve. In fact, I intended to have a collection of pointers, so instead of passing as PC the class*, I decided to pass only the class and just create the smart pointer inside a method of my templated "vector" class. Now it works, thank you all :)