c++ - How to forward declare a template class in namespace std? -
#ifndef __test__ #define __test__ namespace std { template<typename t> class list; } template<typename t> void pop(std::list<t> * l) { while(!l->empty()) l->pop(); } #endif and used function in main. errors. of course, know there more template params std::list (allocator think). but, beside point. have know full template declaration of template class able forward declare it?
edit: wasn't using pointer before - reference. i'll try out pointer.
the problem not can't forward-declare template class. yes, need know of template parameters and defaults able forward-declare correctly:
namespace std { template<class t, class allocator = std::allocator<t>> class list; } but make such forward declaration in namespace std explicitly prohibited standard: only thing you're allowed put in std template specialisation, commonly std::less on user-defined type. else can cite relevant text if necessary.
just #include <list> , don't worry it.
oh, incidentally, name containing double-underscores reserved use implementation, should use test_h instead of __test__. it's not going generate warning or error, if program has clash implementation-defined identifier, it's not guaranteed compile or run correctly: it's ill-formed. prohibited names beginning underscore followed capital letter, among others. in general, don't start things underscores unless know magic you're dealing with.
Comments
Post a Comment