Visit Our UNIX and Linux User Community


Problems with template instantiation in C++


 
Thread Tools Search this Thread
Top Forums Programming Problems with template instantiation in C++
# 1  
Old 08-07-2009
Problems with template instantiation in C++

I use the the g++ 4.3.2 compiler on my linux machine. If I compile the following piece of code I get a bunch of compiler time error. In my opinion the compiler
have all information to process the code properly. I can't imagine, what's
going wrong?

Sorry for the long code portion, but I have reduced the code as much as possible! You can view the source code and additionally the compiler error message!

Code:
#ifndef   __EDIFACT_FACETTE__H__                                                
#  define __EDIFACT_FACETTE__H__                                                

#include <iosfwd>
#include <ios>   
#include <locale>
#include <iostream>
#include <streambuf>
#include <locale>   
#include <string>   




namespace Edifact {
        using namespace std;

class         EdifactFormat;
class         ElementFormat;

template <class Ch, class Tr, class In> class   EdifactSibling;
template <class Ch, class Tr, class In> class   ElementSibling;

template <class Ch, class Tr, class In> class                Request;
template <class Ch, class Tr, class In> class         ServiceRequest;

template <class Ch, class Tr> class ServiceCharacters;
template <class Ch, class Tr> class Definition;       
template <class Ch, class Tr> class UNOCharTraits;    
template <class Ch, class Tr> class EdifactSet;       
template <class Ch, class Tr> class Standard;         

template <class Ch, class Tr, class In> class Carrier;
template <class Ch, class Tr, class In> class Line;   
template <class Ch, class Tr, class In> class Channel;

template <class Ch, class Tr, class In> class Syntax;

template <class Ch, class Tr> class Discriminante;
template <class Ch, class Tr> class EdifactEvent; 
template <class Ch, class Tr> class ServiceEvent; 

template <class Ch, class Tr, class In>
        const EdifactSibling<Ch, Tr, In> *edifact_sibling(
                                        basic_istream<Ch, Tr> &is);

template <class Ch, class Tr = char_traits<Ch>,
                                        class In = istreambuf_iterator<Ch, Tr> >
class Edifact_get: public std::locale::facet {                                  
public:                                                                         
        typedef Ch   char_type;                                                 
        typedef Tr traits_type;                                                 
        typedef In   iter_type;                                                 
        typedef         ElementFormat un_element;                               
        typedef         EdifactFormat un_edifact;                               

        typedef Edifact_get<Ch, Tr, In> facet_type;

        typedef ServiceCharacters<Ch, Tr> service;
        typedef EdifactSet<Ch, Tr> un_set;        

        typedef EdifactSibling<Ch, Tr, In> sibling_type;

        typedef    Discriminante<Ch, Tr    > discriminante_type;
        typedef     EdifactEvent<Ch, Tr    >         event_type;
        typedef     ServiceEvent<Ch, Tr    > service_event_type;

        typedef             Line<Ch, Tr, In>          line_type;
        typedef          Carrier<Ch, Tr, In>       carrier_type;

        typedef                Request<Ch, Tr, In>                  request_type;                                                                               
        typedef         ServiceRequest<Ch, Tr, In>          service_request_type;                                                                               

        typedef request_type *(Edifact_get::*Postfix)();

        typedef std::basic_string <Ch, Tr>  string_type;
        typedef std::basic_ios    <Ch, Tr>     ios_type;
        typedef std::basic_istream<Ch, Tr> istream_type;

protected:

        Edifact_get();

        virtual ~Edifact_get();

public:
        In get(In begin, In end, ios_type &s, ios_base::iostate &r,
                                        string_type &element);     

        In begin_of_element(In begin, In end, ios_type &s,
                                        ios_base::iostate &r, un_element &locale, bool mandatory);                                                              

        In trigger(In begin, In end, ios_type &s, ios_base::iostate &error);

        In end_of_element(In begin, In end, ios_type &s, ios_base::iostate &r);

        void set_character_set(ios_type &s, ios_base::iostate &r,
                                        string_type &uno);       

        void set_service_characters(ios_type &s, ios_base::iostate &r,
                                        string_type &una);            

        const string &_0052(ios_type &s) const;

        void init(event_type *edifact, ios_type &s);
        void destroy(ios_type &s);                  

protected:  friend const sibling_type *Edifact::edifact_sibling
                        <Ch, Tr, In>(basic_istream<Ch, Tr> &s);

        sibling_type *edifact_sibling(ios_type &s);

        sibling_type *edifact_sibling(istream_type &is);

        const sibling_type *edifact_sibling(ios_type &s) const;

        const sibling_type *edifact_sibling(istream_type &is) const;

        int status() const;

public:
        discriminante_type *discriminante(ios_type &s) const;

        void set_discriminante(ios_type &s, discriminante_type *value);

        int discriminante() const;

};

template <class Ch, class Tr = char_traits<Ch>,
                 class In = istreambuf_iterator<Ch, Tr> >
class edifact_get: public Edifact_get<Ch, Tr, In> {      
public:                                                  
        static typename locale::id id;                   
};                                                       

} // namespace Edifact

#endif

namespace Edifact {
        using namespace std;

template <class Ch, class Tr = char_traits<char>,
                 class In = istreambuf_iterator<char, char_traits<char> > >
class Typedefines {                                                        
        public:                                                            
                typedef const string &(                                    
                        Edifact_get<Ch, Tr, In>::*Discriminante)(          
                                basic_ios<Ch, Tr> &s) const;               
                typedef In (Edifact_get<Ch, Tr, In>::*SetGetElementFormat)(
                                In begin, In end, basic_ios<Ch, Tr> &s, ios_base::iostate &r,                                                                   
                                ElementFormat   &token, bool mandatory);        
                typedef In (Edifact_get<Ch, Tr, In>::*Terminator)(              
                                In begin, In end, basic_ios<Ch, Tr> &s, ios_base::iostate &r);                                                                  
                typedef void (Edifact_get<Ch, Tr, In>::*Inspector)(             
                                basic_ios<Ch, Tr> &s, ios_base::iostate &r,     
                                basic_string<Ch, Tr> &monitor);                 
};                                                                              

template class Typedefines<char>;

export template <class Ch, class Tr, class In>
const EdifactSibling<Ch, Tr, In> *edifact_sibling(
                                basic_istream<Ch, Tr> &is) {
        const EdifactSibling<Ch, Tr, In> *status;           

        status = use_facet<Edifact::edifact_get<Ch, Tr, In> >(
                                        is.getloc()).edifact_sibling(is);
        return status;                                                   
}                                                                        

template const EdifactSibling<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > > *edifact_sibling                                                                               
                 <char, char_traits<char>,                                      
                 istreambuf_iterator<char, char_traits<char> > >(istream &is);  

export template <class Ch, class Tr, class In>
const string &discriminante(basic_istream<Ch, Tr> &is,
                                typename Typedefines<Ch, Tr, In>::Discriminante disc) {                                                                         
        static string empty;                                                    
        const string &result = empty;                                           

                result = (use_facet<edifact_get<Ch, Tr, In> >(is.getloc()).*disc)(is);                                                                          
        return result;                                                          
}                                                                               

template const string &discriminante<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(istream &is,
                                Typedefines<char>::Discriminante disc);      

export template <class Ch, class Tr, class In>
const string &_0052(basic_istream<Ch, Tr> &is) {
        return discriminante(is, &Edifact_get<Ch, Tr, In>::_0052);
}                                                                 

template const string &_0052<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(istream &is);

export template <class Ch, class Tr, class In>
bool skipped(basic_istream<Ch, Tr> &is) {     
        return skipped(edifact_sibling(is));  
}                                             

template bool skipped<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(istream &is);

export template <class Ch, class Tr, class In>
bool omit(basic_istream<Ch, Tr> &is) {        
        return omit(edifact_sibling(is));     
}                                             

template bool omit<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(istream &is);

export template <class Ch, class Tr, class In>
bool exist(basic_istream<Ch, Tr> &is) { return !omit(is); }

template bool exist<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(istream &is);

export template <class Ch, class Tr, class In>
basic_istream<Ch, Tr> &operator>>(basic_istream<Ch, Tr> &is,
                                basic_string<Ch, Tr> &s) {  
        ios_base::iostate state = ios_base::goodbit;  // good
        In eos;                                              
                use_facet<edifact_get<Ch, Tr, In> >(         
                                                is.getloc()).get(is, eos, is, state, s);                                                                        
        return is;                                                              
}                                                                               

template istream &operator>><char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(istream &is, string &s);                                                                       

export template <class Ch, class Tr, class In, class Ef, typename SgF>
basic_istream<Ch, Tr> &dataScanStatus(                                
                                basic_istream<Ch, Tr> &is,            
                                Ef &un_format, bool mandatory, SgF status) {
        ios_base::iostate state = ios_base::goodbit;  // good               
        In eos;                                                             

                (use_facet<edifact_get<Ch, Tr, In> >(is.getloc()).*status)
                                (is, eos, is, state, un_format, mandatory);
        return is;                                                         
}                                                                          

template istream &dataScanStatus<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> >, ElementFormat,
                Typedefines<char>::SetGetElementFormat>(                      
                                                istream &is, ElementFormat &un_format,                                                                          
                                bool mandatory, Typedefines<char>::SetGetElementFormat sgef);                                                                   

export template <class Ch, class Tr, class In>
basic_istream<Ch, Tr> &control(basic_istream<Ch, Tr> &is,
                                typename Typedefines<Ch, Tr, In>::Terminator terminator) {                                                                      
        In eos;                                                                 
        ios_base::iostate r = ios_base::goodbit;                                

                (use_facet<edifact_get<Ch, Tr, In> >(
                                                                is.getloc()).*terminator)(is, eos, is, r);                                                      
        return is;                                                              
}                                                                               

template istream &control<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(istream &is,
                                Typedefines<char>::Terminator terminator);   

export template <class Ch, class Tr, class In>
basic_istream<Ch, Tr> &monitoring(basic_istream<Ch, Tr> &is,
                                basic_string<Ch, Tr> &monitor,
                                typename Typedefines<Ch, Tr, In>::Inspector inspector) {                                                                        
        ios_base::iostate r = ios_base::goodbit;                                

                (use_facet<edifact_get<Ch, Tr, In> >(
                                                                        is.getloc()).*inspector)(is, r, monitor);                                               
        return is;                                                              
}                                                                               

template istream &monitoring<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(
                                                 istream &is, string &monitor,
                                Typedefines<char>::Inspector inspector);      

export template <class Ch, class Tr, class In>
basic_istream<Ch, Tr> &begin_of_element(      
                                basic_istream<Ch, Tr> &is, ElementFormat &un_element,                                                                           
                                bool mandatory) {                               
        return dataScanStatus(is, un_element, mandatory,                        
                                        &Edifact_get<Ch, Tr, In>::begin_of_element);                                                                            
}                                                                               

template istream &begin_of_element<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(
                                                 istream &is, ElementFormat &un_element,                                                                        
                                bool mandatory);                                

export template <class Ch, class Tr, class In>
basic_istream<Ch, Tr> &end_of_element(basic_istream<Ch, Tr> &is) {
        return control(is, &Edifact_get<Ch, Tr, In>::end_of_element);
}                                                                    

template istream &end_of_element<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(istream &is);

export template <class Ch, class Tr, class In>
basic_istream<Ch, Tr> &trigger(basic_istream<Ch, Tr> &is) {
        return control(is, &Edifact_get<Ch, Tr, In>::trigger);
}

template istream &trigger<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(istream &is);

export template <class Ch, class Tr, class In>
basic_istream<Ch, Tr> &set_service_characters(
                                basic_istream<Ch, Tr> &is, basic_string<Ch, Tr>&monitor) {
        return monitoring(is, monitor,
                                        &Edifact_get<Ch, Tr, In>::set_service_characters);
}

template istream &set_service_characters<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(
                                                 istream &is, string &monitor);

export template <class Ch, class Tr, class In>
basic_istream<Ch, Tr> &set_character_set(basic_istream<Ch, Tr> &is,
                                basic_string<Ch, Tr> &monitor) {
        return monitoring(is, monitor, &Edifact_get<Ch, Tr, In>::set_character_set);
}

template istream &set_character_set<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(
                                                 istream &is, string &monitor);

} // namespace Edifact

Quote:
xing.cc:163: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:178: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:192: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:200: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:208: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:216: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:222: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:235: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:253: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:268: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:284: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:297: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:305: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:313: warning: keyword ‘export' not implemented, and will be ignored
xing.cc:324: warning: keyword ‘export' not implemented, and will be ignored
xing.cc: In function ‘const std::string& Edifact::discriminante(std::basic_istream<_CharT, _Traits>&, typename Edifact::Typedefines<Ch, Tr, In>::Discriminante) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:190: instantiated from here
xing.cc:184: error: passing ‘const std::string' as ‘this' argument of ‘std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' discards qualifiers
xing.cc: In function ‘const std::string& Edifact::_0052(std::basic_istream<_CharT, _Traits>&) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:198: instantiated from here
xing.cc:194: error: no matching function for call to ‘discriminante(std::basic_istream<char, std::char_traits<char> >&, const std::string& (Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >::*)(std::basic_ios<char, std::char_traits<char> >&)const)'
xing.cc: In function ‘bool Edifact::skipped(std::basic_istream<_CharT, _Traits>&) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:206: instantiated from here
xing.cc:202: error: no matching function for call to ‘edifact_sibling(std::basic_istream<char, std::char_traits<char> >&)'
xing.cc: In function ‘bool Edifact::omit(std::basic_istream<_CharT, _Traits>&) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:214: instantiated from here
xing.cc:210: error: no matching function for call to ‘edifact_sibling(std::basic_istream<char, std::char_traits<char> >&)'
xing.cc: In function ‘bool Edifact::exist(std::basic_istream<_CharT, _Traits>&) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:220: instantiated from here
xing.cc:217: error: no matching function for call to ‘omit(std::basic_istream<char, std::char_traits<char> >&)'
xing.cc: In function ‘std::basic_istream<_CharT, _Traits>& Edifact::operator>>(std::basic_istream<_CharT, _Traits>&, std::basic_string<Ch, Tr, std::allocator<_CharT> >&) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:233: instantiated from here
xing.cc:227: error: passing ‘const Edifact::edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >' as ‘this' argument of ‘In Edifact::Edifact_get<Ch, Tr, In>::get(In, In, std::basic_ios<_CharT, _Traits>&, std::_Ios_Iostate&, std::basic_string<Ch, Tr, std::allocator<_CharT> >&) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]' discards qualifiers
xing.cc: In function ‘std::basic_istream<_CharT, _Traits>& Edifact::dataScanStatus(std::basic_istream<_CharT, _Traits>&, Ef&, bool, SgF) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >, Ef = Edifact::ElementFormat, SgF = std::istreambuf_iterator<char, std::char_traits<char> > (Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >::*)(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::basic_ios<char, std::char_traits<char> >&, std::_Ios_Iostate&, Edifact::ElementFormat&, bool)]':
xing.cc:251: instantiated from here
xing.cc:242: error: invalid conversion from ‘const Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >*' to ‘Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >*'
xing.cc: In function ‘std::basic_istream<_CharT, _Traits>& Edifact::control(std::basic_istream<_CharT, _Traits>&, typename Edifact::Typedefines<Ch, Tr, In>::Terminator) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:266: instantiated from here
xing.cc:259: error: invalid conversion from ‘const Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >*' to ‘Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >*'
xing.cc: In function ‘std::basic_istream<_CharT, _Traits>& Edifact::monitoring(std::basic_istream<_CharT, _Traits>&, std::basic_string<Ch, Tr, std::allocator<_CharT> >&, typename Edifact::Typedefines<Ch, Tr, In>::Inspector) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:282: instantiated from here
xing.cc:274: error: invalid conversion from ‘const Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >*' to ‘Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >*'
xing.cc: In function ‘std::basic_istream<_CharT, _Traits>& Edifact::begin_of_element(std::basic_istream<_CharT, _Traits>&, Edifact::ElementFormat&, bool) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:295: instantiated from here
xing.cc:289: error: no matching function for call to ‘dataScanStatus(std::basic_istream<char, std::char_traits<char> >&, Edifact::ElementFormat&, bool&, std::istreambuf_iterator<char, std::char_traits<char> > (Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >::*)(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::basic_ios<char, std::char_traits<char> >&, std::_Ios_Iostate&, Edifact::ElementFormat&, bool))'
xing.cc: In function ‘std::basic_istream<_CharT, _Traits>& Edifact::end_of_element(std::basic_istream<_CharT, _Traits>&) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:303: instantiated from here
xing.cc:299: error: no matching function for call to ‘control(std::basic_istream<char, std::char_traits<char> >&, std::istreambuf_iterator<char, std::char_traits<char> > (Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >::*)(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::basic_ios<char, std::char_traits<char> >&, std::_Ios_Iostate&))'
xing.cc: In function ‘std::basic_istream<_CharT, _Traits>& Edifact::trigger(std::basic_istream<_CharT, _Traits>&) [with Ch = char, Tr = std::char_traits<char>,In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:311: instantiated from here
xing.cc:307: error: no matching function for call to ‘control(std::basic_istream<char, std::char_traits<char> >&, std::istreambuf_iterator<char, std::char_traits<char> > (Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >::*)(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::basic_ios<char, std::char_traits<char> >&, std::_Ios_Iostate&))'
xing.cc: In function ‘std::basic_istream<_CharT, _Traits>& Edifact::set_service_characters(std::basic_istream<_CharT, _Traits>&, std::basic_string<Ch, Tr, std::allocator<_CharT> >&) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:322: instantiated from here
xing.cc:317: error: no matching function for call to ‘monitoring(std::basic_istream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, void (Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >::*)(std::basic_ios<char, std::char_traits<char> >&, std::_Ios_Iostate&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&))'
xing.cc: In function ‘std::basic_istream<_CharT, _Traits>& Edifact::set_character_set(std::basic_istream<_CharT, _Traits>&, std::basic_string<Ch, Tr, std::allocator<_CharT> >&) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]':
xing.cc:332: instantiated from here
xing.cc:327: error: no matching function for call to ‘monitoring(std::basic_istream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, void (Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >::*)(std::basic_ios<char, std::char_traits<char> >&, std::_Ios_Iostate&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&))'
# 2  
Old 08-09-2009
The first several lines about the "export" keyword should be pretty clear: "export", used to enable a separation of declaration and definition of template classes/functions, is not supported by GCC.
A common work around to avoid this deprecated keyword and still stay on top of things is to do sort of a reverse include: Provide prototypes (with normal header extension) and definitions (usually with an "impl" ext.) in distinct files as usual but include the implementation file at the end of the header file. This is necessary as template instantiation requires presence of definition so it can instantiate the template "in one go".

Another error I spotted at a quick glance is linked with the very last function. Am I right in assuming it should be a total specialization of the function above? Then it should read "template <>". Of course, also here the function's definition is missing.

Hth, Gunther
# 3  
Old 08-11-2009
I thank you for your help.

Quote:
The first several lines about the "export" keyword should be pretty clear: "export", used to enable a separation of declaration and definition of template classes/functions, is not supported by GCC.
A common work around to avoid this deprecated keyword and still stay on top of things is to do sort of a reverse include: Provide prototypes (with normal header extension) and definitions (usually with an "impl" ext.) in distinct files as usual but include the implementation file at the end of the header file. This is necessary as template instantiation requires presence of definition so it can instantiate the template "in one go".
I know, that g++ doesn't support the export keyword. But as time goes, this fact can be changed, or this keyword will be abolished. Therefore the I included this feature.
I have shorten the code to publish it on this forum. In the real world this file is scattered over several files. The core module of this project is about 20000 lines. Every additional module can be rough about 100 000 lines or the multiple size. Therefore I concluded to separate the compile units.

Quote:
Another error I spotted at a quick glance is linked with the very last function. Am I right in assuming it should be a total specialization of the function above? Then it should read "template <>". Of course, also here the function's definition is missing.
I have included the "<>" glyphes into the code. The result is, that the compile errors go away. But I have looked into the object file with the nm tool and I couldn't seen any instantiate function. That is not really what I intended.

MartinM09.
# 4  
Old 08-12-2009
Quote:
couldn't seen any instantiate function
Have you instantiated one yourself? Because if you never "fill out" the template, you won't see one in the object code.
# 5  
Old 08-22-2009
Dear Gunther,

I have changed my code to

Code:
export template <class Ch, class Tr, class In, class Ef, typename SgF>
basic_istream<Ch, Tr> &dataScanStatus(                                
                                basic_istream<Ch, Tr> &is,            
                                Ef &un_format, bool mandatory, SgF status) {
        ios_base::iostate state = ios_base::goodbit;  // good               
        In eos;                                                             

                (use_facet<Edifact_get<Ch, Tr, In> >(is.getloc()).*status)
                                (is, eos, is, state, un_format, mandatory);
        return is;                                                         
}                                                                          

template istream &dataScanStatus<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> >, ElementFormat,
                Typedefines<char>::SetGetElementFormat>(                      
                                                istream &is, ElementFormat &un_format,                                                                          
                                bool mandatory, istreambuf_iterator<char, char_traits<char> >                                                                   
                           (Edifact_get<char>::*sgef)(                          
                                           istreambuf_iterator<char, char_traits<char> > begin,                                                                 
                                           istreambuf_iterator<char, char_traits<char> > end,                                                                   
                                           basic_ios<char> &s, ios_base::iostate &r,                                                                            
                                           ElementFormat &token, bool mandatory));                                                                              

export template <class Ch, class Tr, class In>
basic_istream<Ch, Tr> &begin_of_element(      
                                basic_istream<Ch, Tr> &is, ElementFormat &un_element,                                                                           
                                bool mandatory) {                               
        return dataScanStatus(is, un_element, mandatory,                        
                                        &Edifact_get<Ch, Tr, In>::begin_of_element);                                                                            
}                                                                               

template istream &begin_of_element<char, char_traits<char>,
                 istreambuf_iterator<char, char_traits<char> > >(
                                                 istream &is, ElementFormat &un_element,                                                                        
                                bool mandatory);

As far as I could see, I should get the instantiated function dataScanStatus(..) and
begin_of_element(..). But the g++ compiler throws the errors
Code:
                                                                          
xing.class.cc:313:   instantiated from here                                     
xing.class.cc:307: error: no matching function for call to ‘dataScanStatus(std::basic_istream<char, std::char_traits<char> >&, Edifact::ElementFormat&, bool&, std::istreambuf_iterator<char, std::char_traits<char> > (Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >::*)(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::basic_ios<char, std::char_traits<char> >&, std::_Ios_Iostate&, Edifact::ElementFormat&, bool))’

and
Code:
xing.class.cc: In function ‘std::basic_istream<_CharT, _Traits>& Edifact::dataScanStatus(std::basic_istream<_CharT, _Traits>&, Ef&, bool, SgF) [with Ch = char,Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >, Ef = Edifact::ElementFormat, SgF = std::istreambuf_iterator<char, std::char_traits<char> > (Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >::*)(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::basic_ios<char, std::char_traits<char> >&, std::_Ios_Iostate&, Edifact::ElementFormat&, bool)]’:
xing.class.cc:262:   instantiated from here
xing.class.cc:248: error: invalid conversion from ‘const Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >*’ to ‘Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >*’

I see no opportunity to avoid the "Typedefines<char>::SetGetElementFormat by an
element to class pointer in the template instantiation.
Another problem of the introducing code is the following error:
Code:
xing.class.cc: In function ‘std::basic_istream<_CharT, _Traits>& Edifact::control(std::basic_istream<_CharT, _Traits>&, In (Edifact::Edifact_get<Ch, Tr, In>::*)(In, In, std::basic_ios<_CharT, _Traits>&, std::_Ios_Iostate&)) [with Ch = char, Tr = std::char_traits<char>, In = std::istreambuf_iterator<char, std::char_traits<char> >]’:
xing.class.cc:282:   instantiated from here
xing.class.cc:271: error: invalid conversion from ‘const Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >*’ to ‘Edifact::Edifact_get<char, std::char_traits<char>, std::istreambuf_iterator<char, std::char_traits<char> > >*’

I can't see the reason, why the compiler want to cast the const attribute away.
I cannot image, what is wrong?

MartinM09
# 6  
Old 08-23-2009
Maybe you could mark which lines of your code excerpt are the relevant ones.
Btw, where's the function body of your template specialization for "dataScanStatus"?

PS: I also suggest using gstlfilt. It will also shorten your error messages.
# 7  
Old 08-23-2009
Dear Gunther,

I will repeat the line numbered code here
Code:
   241  export template <class Ch, class Tr, class In, class Ef, typename SgF>  
   242  basic_istream<Ch, Tr> &dataScanStatus(                                  
   243                                  basic_istream<Ch, Tr> &is,              
   244                                  Ef &un_format, bool mandatory, SgF status) {                                                                            
   245          ios_base::iostate state = ios_base::goodbit;  // good           
   246          In eos;                                                         
   247                                                                          
   248                  (use_facet<Edifact_get<Ch, Tr, In> >(is.getloc()).*status)                                                                              
   249                                  (is, eos, is, state, un_format, mandatory);                                                                             
   250          return is;                                                      
   251  }                                                                       
   252                                                                          
   253  template istream &dataScanStatus<char, char_traits<char>,               
   254                   istreambuf_iterator<char, char_traits<char> >, ElementFormat,                                                                          
   255                  Typedefines<char>::SetGetElementFormat>(                
   256                                                  istream &is, ElementFormat &un_format,                                                                  
   257                                  bool mandatory, istreambuf_iterator<char, char_traits<char> >                                                           
   258                             (Edifact_get<char>::*sgef)(                  
   259                                             istreambuf_iterator<char, char_traits<char> > begin,                                                         
   260                                             istreambuf_iterator<char, char_traits<char> > end,                                                           
   261                                             basic_ios<char> &s, ios_base::iostate &r,                                                                    
   262                                             ElementFormat &token, bool mandatory));                                                                      
   263                                                                          
   264  export template <class Ch, class Tr, class In>                          
   265  basic_istream<Ch, Tr> &control(basic_istream<Ch, Tr> &is,               
   266                                  In (Edifact_get<Ch, Tr, In>::*terminator)(In begin,                                                                     
   267                                             In end, basic_ios<Ch, Tr> &s, ios_base::iostate &r)) {                                                       
   268          In eos;                                                         
   269          ios_base::iostate r = ios_base::goodbit;                        
   270                                                                          
   271                  (use_facet<Edifact_get<Ch, Tr, In> >(                   
   272                                                                  is.getloc()).*terminator)(is, eos, is, r);                                              
   273          return is;                                                      
   274  }                                                                       
   275                                                                          
   276  template istream &control<char, char_traits<char>,                      
   277                   istreambuf_iterator<char, char_traits<char> > >(istream &is,                                                                           
   278                                  istreambuf_iterator<char, char_traits<char> >                                                                           
   279                                  (Edifact_get<char>::*terminator)(       
   280                                                  istreambuf_iterator<char, char_traits<char> > begin,                                                    
   281                                                  istreambuf_iterator<char, char_traits<char> > end,                                                      
   282                                                  basic_ios<char> &s, ios_base::iostate &r));                                                             
   283  
   302  export template <class Ch, class Tr, class In>                          
   303  basic_istream<Ch, Tr> &begin_of_element(                                
   304                                  basic_istream<Ch, Tr> &is, ElementFormat &un_element,                                                                   
   305                                  bool mandatory) {                       
   306          return dataScanStatus(is, un_element, mandatory,                
   307                                          &Edifact_get<Ch, Tr, In>::begin_of_element);                                                                    
   308  }                                                                       
   309                                                                          
   310  template istream &begin_of_element<char, char_traits<char>,             
   311                   istreambuf_iterator<char, char_traits<char> > >(       
   312                                                   istream &is, ElementFormat &un_element,                                                                
   313                                  bool mandatory);

The stlfilt program produces following output
Code:
xing.class.cc: istreambuf_iterator<char, char_traits<char> > function ‘const
    string & Edifact::discriminante(                                        
        basic_istream<_CharT, _Traits> &, const string & (                  
            Edifact::Edifact_get<                                           
                char, char_traits<char>, istreambuf_iterator<               
                    char, char_traits<char> > >::*)(                        
            basic_ios<_CharT, _Traits> &)const)’:                           
xing.class.cc:190:   instantiated from here                                 
xing.class.cc:183: error: passing ‘const string’ as ‘this’ argument of      
    ‘string & string::operator=(const string &)’ discards qualifiers        
xing.class.cc: istreambuf_iterator<char, char_traits<char> > function ‘bool 
    Edifact::skipped(basic_istream<_CharT, _Traits> &)’:                    
xing.class.cc:209:   instantiated from here                                 
xing.class.cc:205: error: No match for ‘edifact_sibling(istream &)’         
xing.class.cc: istreambuf_iterator<char, char_traits<char> > function ‘bool 
    Edifact::omit(basic_istream<_CharT, _Traits> &)’:                       
xing.class.cc:220:   instantiated from here                                 
xing.class.cc:216: error: No match for ‘edifact_sibling(istream &)’         
xing.class.cc: istreambuf_iterator<char, char_traits<char> > function ‘bool 
    Edifact::exist(basic_istream<_CharT, _Traits> &)’:                      
xing.class.cc:226:   instantiated from here                                 
xing.class.cc:223: error: No match for ‘omit(istream &)’                    
xing.class.cc: istreambuf_iterator<char, char_traits<char>> function ‘      
    basic_istream<_CharT, _Traits> & Edifact::operator>>(                   
        basic_istream<_CharT, _Traits> &, basic_string<char, char_traits<char>>
        &)’:                                                                   
xing.class.cc:239:   instantiated from here                                    
xing.class.cc:233: error: passing ‘const Edifact::Edifact_get<                 
        char, char_traits<char>, istreambuf_iterator<char, char_traits<        
                char>>>’ as ‘this’ argument of ‘istreambuf_iterator<           
        char, char_traits<char>                                                
    > Edifact::Edifact_get<                                                    
        char, char_traits<char>, istreambuf_iterator<char, char_traits<char> > 
    >::get(                                                                    
        istreambuf_iterator<char, char_traits<char> >, istreambuf_iterator<    
            char, char_traits<char> >, basic_ios<_CharT, _Traits> &,           
        _Ios_Iostate &, basic_string<char, char_traits<char> > &)’ discards    
    qualifiers                                                                 
xing.class.cc: istreambuf_iterator<char, char_traits<char> > function ‘        
    basic_istream<_CharT, _Traits> & Edifact::dataScanStatus(                  
        basic_istream<_CharT, _Traits> &, Edifact::ElementFormat &, bool,      
        istreambuf_iterator<char, char_traits<char> > (                        
            Edifact::Edifact_get<                                              
                char, char_traits<char>, istreambuf_iterator<                  
                    char, char_traits<char> > >::*)(                           
            istreambuf_iterator<char, char_traits<char> >, istreambuf_iterator<
                char, char_traits<char> >, basic_ios<char, char_traits<char> > 
            &, _Ios_Iostate &, Edifact::ElementFormat &, bool))’:              
xing.class.cc:262:   instantiated from here                                    
xing.class.cc:248: error: invalid conversion from ‘const Edifact::Edifact_get< 
        char, char_traits<char>, istreambuf_iterator<char, char_traits<char> > 
    > *’ to ‘Edifact::Edifact_get<                                             
        char, char_traits<char>, istreambuf_iterator<char, char_traits<char> > 
    > *’                                                                       
xing.class.cc: istreambuf_iterator<char, char_traits<char> > function ‘        
    basic_istream<_CharT, _Traits> & Edifact::control(                         
        basic_istream<_CharT, _Traits> &, istreambuf_iterator<                 
            char, char_traits<char> > (                                        
            Edifact::Edifact_get<                                              
                char, char_traits<char>, istreambuf_iterator<                  
                    char, char_traits<char> > >::*)(                           
            istreambuf_iterator<char, char_traits<char> >, istreambuf_iterator<
                char, char_traits<char> >, basic_ios<_CharT, _Traits> &,       
            _Ios_Iostate &))’:
xing.class.cc:282:   instantiated from here
xing.class.cc:271: error: invalid conversion from ‘const Edifact::Edifact_get<
        char, char_traits<char>, istreambuf_iterator<char, char_traits<char> >
    > *’ to ‘Edifact::Edifact_get<
        char, char_traits<char>, istreambuf_iterator<char, char_traits<char> >
    > *’
xing.class.cc: istreambuf_iterator<char, char_traits<char> > function ‘
    basic_istream<_CharT, _Traits> & Edifact::monitoring(
        basic_istream<_CharT, _Traits> &, basic_string<char, char_traits<char>
        > &, void (
            Edifact::Edifact_get<
                char, char_traits<char>, istreambuf_iterator<
                    char, char_traits<char> > >::*)(
            basic_ios<char, char_traits<char> > &, _Ios_Iostate &, basic_string<
                char, char_traits<char> > &))’:
xing.class.cc:300:   instantiated from here
xing.class.cc:291: error: invalid conversion from ‘const Edifact::Edifact_get<
        char, char_traits<char>, istreambuf_iterator<char, char_traits<char> >
    > *’ to ‘Edifact::Edifact_get<
        char, char_traits<char>, istreambuf_iterator<char, char_traits<char> >
    > *’
xing.class.cc: istreambuf_iterator<char, char_traits<char> > function ‘
    basic_istream<_CharT, _Traits> & Edifact::begin_of_element(
        basic_istream<_CharT, _Traits> &, Edifact::ElementFormat &, bool)’:
xing.class.cc:313:   instantiated from here
xing.class.cc:307: error: No match for ‘dataScanStatus(
        istream &, Edifact::ElementFormat &, bool &, istreambuf_iterator<
            char, char_traits<char> > (
            Edifact::Edifact_get<
                char, char_traits<char>, istreambuf_iterator<
                    char, char_traits<char> > >::*)(
            istreambuf_iterator<char, char_traits<char> >, istreambuf_iterator<
                char, char_traits<char> >, basic_ios<char, char_traits<char> >
            &, _Ios_Iostate &, Edifact::ElementFormat &, bool))’
xing.class.cc:248: error: invalid conversion from ‘const Edifact::Edifact_get< 
        char, char_traits<char>, istreambuf_iterator<char, char_traits<char> > 
    > *’ to ‘Edifact::Edifact_get<                                             
        char, char_traits<char>, istreambuf_iterator<char, char_traits<char> > 
    > *’                                                                       
xing.class.cc: istreambuf_iterator<char, char_traits<char> > function ‘        
    basic_istream<_CharT, _Traits> & Edifact::control(                         
        basic_istream<_CharT, _Traits> &, istreambuf_iterator<                 
            char, char_traits<char> > (                                        
            Edifact::Edifact_get<                                              
                char, char_traits<char>, istreambuf_iterator<                  
                    char, char_traits<char> > >::*)(                           
            istreambuf_iterator<char, char_traits<char> >, istreambuf_iterator<
                char, char_traits<char> >, basic_ios<_CharT, _Traits> &,       
            _Ios_Iostate &))’:

The function dataScanStatus() is defined in line 241 and instantiated in line 253.
The function control is defined in 264 and instantiated in line 276.
I don't can see the mistake and I hope you can give me any hint.

MartinM09

Previous Thread | Next Thread
Test Your Knowledge in Computers #354
Difficulty: Medium
gawk is the only awk implementation that makes serious progress implementing internationalization and localization and TCP/IP networking.
True or False?

6 More Discussions You Might Find Interesting

1. Programming

Calling template at once

Hello Again, I am just wanted to know if we can call the Template using "require_once" at PHP? Any views around happy to discuss. Thanks in Advance (2 Replies)
Discussion started by: AimyThomas
2 Replies

2. Programming

C++ template error

I get some compiling errors about template instantiation :wall: , but I can't find where the syntax errors happens. Can some help me? template<typename Type> class SingleList; template<typename Type> class SingleListNode{ private: friend class SingleList<Type>; SingleListNode() :... (1 Reply)
Discussion started by: 915086731
1 Replies

3. Shell Programming and Scripting

Help with template like solution

hi experts, i'm trying to do this: file1 is a template. might have kinds of 'funny' characters. sample: <body> <form> <p><input type="text" name="abc"/></p> &nbsp; <p><my_content></p> </form> </body> file2 is a file that contains lots of text. this might be very big. might have... (2 Replies)
Discussion started by: xjohnu
2 Replies

4. Programming

Template problem ...

Hi all, Need your help. I am doing a simple template program , getting some error ... here is the code #include <iostream> #include <stdio.h> #include <stdlib.h> #include<iostream> #include<string> #include <sstream> using namespace std; class Base_class { public: Base_class(){... (1 Reply)
Discussion started by: amartya_sock
1 Replies

5. UNIX for Dummies Questions & Answers

vi calling template

Hello. I want to copy temp files when I make a new file by vi. For example, 09:32:52 ~/ $ mkdir test 09:33:03 ~/ $ cd test/ 09:33:09 ~/test/ $ ls 09:33:16 ~/test/ $ vi test.cpp 09:34:37 ~/test/ $ cat test.cpp #include <iostream> int main() { } 09:34:48 ~/test/ $ vi test.bash 09:35:19... (1 Reply)
Discussion started by: Euler04
1 Replies

6. Programming

About template constraints

Hi, i have class template, 1)can i override the copy constructor 2)can we have virtual function in class template if not plz tel why? I tried , compile error comes for me... Thanks Sarwan (0 Replies)
Discussion started by: sarwan
0 Replies

Featured Tech Videos