Re: templating



Hi Bernd,

Thank you for your reply, but this is not an option for me since tClass
in my case is actually derived from a base class in Glib which requires
a parameter. So if I can't pass a parameter then there is no point in
doing this at all for me.

Regards,
Rober


On Sun, 2008-12-21 at 12:07 +0100, Bernd Robertz wrote:
> Hello,
> 
> ok, if I got your problem, you ran into the problem, that you can't pass
> arguments to the template class, because the template class itself is a
> argument.
> 
> You have to write a method wich forks the additional parameters like
> this:
> 
> myNodeClass<tClass> sometpl;
> sometpl.push_back("parameter"); // where parameter is type string
> 
> So the constructor of tClass don't have parameters.
> 
> Just have a look at
> 
> http://www.cppreference.com/wiki/stl/vector/vector_constructors
> 
> There you can define wich type of template the vector should contain,
> but the template data is later.
> 
> If I have missunderstood your problem, or I'm generally wrong, just
> correct Me. :-)
> 
> Greetings
> 
> Bernd
> 
> 
> Am Sonntag, den 21.12.2008, 08:52 +0100 schrieb Robert Rehammar:
> > Hi all,
> > 
> > I'm writing a small program and has bumped in to a problem. It is
> > probably actually C++ related, but since it should be a problem lot's of
> > people here face I'll ask here. I want to do the following:
> > 
> > class tClass {
> > 	tClass (string s) {...};
> > 	...
> > }
> > 
> > class myNodeClass : NodeTree<tClass> {
> > 	myNodeClass (string s) :
> > 		NodeTree<tClass> {
> > 		...
> > 	};
> > }
> > 
> > But this won't compile as the template for NodeTree, tClass, requires a
> > parameter (the string s) and I simply can't figure out how to pass it to
> > the template.
> > 
> > Writing the constructor as
> > 
> > myNodeTree (string s): NodeTree<tClass (s)> won't compile, complaining
> > that s can't appear in a constant expression, so this seem so suggest
> > that I can't template with a class that require any parameters for
> > initiation...
> > 
> > Thanks in advance!
> > 
> > \\Robert Rehammar
> > 
> > _______________________________________________
> > gtkmm-list mailing list
> > gtkmm-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtkmm-list
> 



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