-
October 14th, 2009, 01:13 PM
#1
[RESOLVED] help with template template parameters
Hello gurus!
I need some help understanding template template parameters.
Outline of what I'm trying to do is to pass a template vector which is stored in a map,
to a template class that is expecting a vector.
Sort of like,
Psuedo
Code:
template class Foo<A, vector V, B, std::map M>;
In Foo, create M<std::string, V<B<A > > > X;
Define B like;
template class<A, vector V> B;
Pass X::iterator-second to C; // error here
Simplifying it only using vector works,
but when I adapt this workable solution to the model I want,
I get a compilation error (minGW g++).
I spent all night last night and this morning, but I'm stump.
cut down version of class Foo is
Code:
template
<
typename Device,
template<typename> class Container = std::vector,
template<typename> class Configure = Config,
template<typename, typename> class Registry = std::map
>
class BasicSystem
{
template <typename DeviceTrait>
friend std::ostream& operator<<(std::ostream&, const BasicSystem<DeviceTrait*>&);
public:
BasicSystem();
// UI
ResultCode start();
private:
typedef Registry<Input, Container<Configure<Device*> > > iComponent;
iComponent iDevice;
};
and start() member function is a simple initialization prcedure, like
Code:
//////////////////////////////////////////////////////////////////////////////80
// start method
template
<
typename Device,
template<typename> class Container,
template<typename> class Configure,
template<typename, typename> class Registry
>
ResultCode BasicSystem<Device, Container, Configure, Registry>::start()
{
// temporary test
typename iComponent::iterator iter = iDevice.begin();
iter->second.at(0).load("loadme.conf");
///// error here /////
iter->second.at(0).initDevice(iter->second.at(0));
return 0;
}
and the template class that I'm trying to pass to is
Code:
template <typename DeviceTrait, template<typename> class Container = std::vector>
class Config
{
public:
Config();
// UI
Bool load(CRString);
ResultCode initDevice(Container<DeviceTrait*>&, Bool doShow = true);
};
and initDevice method is defined like
Code:
template <typename DeviceTrait, template<typename> class Container>
ResultCode
Config<DeviceTrait, Container>::initDevice(Container<DeviceTrait*>& ref, Bool doShow)
{
std::for_each(ref.begin(), ref.end(),
std::bind2nd(std::mem_fun(&DeviceTrait::init), doShow));
return 19;
}
The compiler keeps telling me that there's no matching functioncall to initDevice(),
but it is myunderstanding that I'm correctly (but apparently wrong) passing a vector.
I'd appreciate if anyone can help.
Thanks
Edit: All these classes are defined in a namespace, if that matters... I'm not sure.
Last edited by potatoCode; October 14th, 2009 at 01:35 PM.
-
October 14th, 2009, 02:13 PM
#2
Re: help with template template parameters
this should be wrong:
Code:
template<typename> class Container = std::vector, //...
because vector takes (at least) two template parameters. Thus, it should be "template<typename,typename> class Container".
-
October 14th, 2009, 02:59 PM
#3
Re: help with template template parameters
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
October 14th, 2009, 07:38 PM
#4
Re: help with template template parameters
Hi superbonzo and souldog!
You guys are correct.
I followed the reference material souldog provided and ta-da, it works.
I was at least aware of how std::vector was declared
(thus wrongly omitting second template default parameter)
But I'm still far from having a solid understanding why I must explicitly do this...
...except a feeling that it somehow relates to how one fully forward declares std::string... No?
Thanks for the help two of you!
Edit:
(and thanks to anyone who might have read and thought about helping but didn't have time )
Last edited by potatoCode; October 14th, 2009 at 07:41 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|