Sponsored Content
Top Forums Programming Problems with template instantiation in C++ Post 302346506 by MartinM09 on Saturday 22nd of August 2009 03:06:36 PM
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 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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
All times are GMT -4. The time now is 10:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy