At this point I'm actually thinking about inheriting from Parameter and overriding the virtual print() function with an empty function.... that would take care of the problem without having to modify libMesh... What do you guys think?
Derek On Mon, Dec 22, 2008 at 1:38 PM, Derek Gaston <[email protected]> wrote: > Ok - I give up... someone tell me what the hell I'm doing wrong. I'm > trying to add the following function to parameters.h (right underneath the > generic version): > template <typename T> > inline > void Parameters::Parameter<std::vector<T> >::print (std::ostream& os) const > { > for (unsigned int i=0; i<_value.size(); i++) > os << _value[i] << " "; > } > > And I get errors: > > invalid use of undefined type 'class Parameters::Parameter<std::vector<T, > std::allocator<_CharT> > >' > /Users/gastdr/projects/libmesh/include/utils/parameters.h:163: error: > declaration of 'class Parameters::Parameter<std::vector<T, > std::allocator<_CharT> > >' > /Users/gastdr/projects/libmesh/include/utils/parameters.h:260: error: > template definition of non-template 'void > Parameters::Parameter<std::vector<T, std::allocator<_CharT> > > >::print(std::ostream&) const' > /Users/gastdr/projects/libmesh/include/utils/parameters.h: In member > function 'void Parameters::Parameter<std::vector<T, std::allocator<_CharT> > > >::print(std::ostream&) const': > > > But... if I do: > > template <> > inline > void Parameters::Parameter<std::vector<Real> >::print (std::ostream& os) > const > { > for (unsigned int i=0; i<_value.size(); i++) > os << _value[i] << " "; > } > > Like normal template specialization.... it works fine. I've tried looking > this up in various places.... and from what I can see I'm doing it > correctly.... so it's time for some outside advice. I've also tried > hundreds of permutations.... and just can't get the damn thing to go. > > Thanks! > Derek > > > On Tue, Dec 16, 2008 at 8:17 PM, Benjamin Kirk <[email protected]>wrote: > >> > os << _value; >> > >> > This doesn't work if the parameter type is something like a >> > std::vector... it won't even compile. Any ideas on dealing with >> > this? For now, we've just commented out that line of code (we don't >> > need to print the parameters) and continued on.... but what is the >> > correct solution? >> >> Hmm... Create a generic <typename T> (as is currently done), and also add >> a >> <std::vector<typename T> > specialization: >> >> template <typename T> >> inline >> void Parameters::Parameter<T>::print (std::ostream& os) const >> { >> os << _value; >> } >> >> template <std::vector< typename T> > >> inline >> void Parameters::Parameter<T>::print (std::ostream& os) const >> { >> for (unsinged int p=0; ...) >> } >> >> Will that do it? >> >> -Ben >> >> >> >
------------------------------------------------------------------------------
_______________________________________________ Libmesh-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libmesh-devel
