Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

template - example from

24 views
Skip to first unread message

Gerhard Wolf

unread,
Sep 5, 2015, 2:19:42 AM9/5/15
to
Hi,
i am not so experienced in template programing as I would like to be, so
i have some questions to Stefans templat example in the "A Preferred or
better Way?" Re-Post.

I tried to compile this code with bcc64. it drops an error:

Implicit instantiation of undefined template
'std::basic_stringstream<char, std::char_traits<char>,
std::allocator<char> >'

i changed the line
scanner s
to
scanner * s
which solved this problem.

If the prior line compiles with a other compiler is ist a compiler
feature/setting?

This change produces 'member-reference basetype 'T *' is no struct or
union' errors on all 's' calls.

how can i change this?


---her Stephans code---------------------------------------------

#include <iostream>
#include <ostream>
#include <sstream>

template< typename scanner >struct parser
{ scanner s; parser( char const * s ): s{ s } {}
int numeral(){ return s.get() - '0'; }
int prefix(){ int sign = 1;
while( '-' == s.peek() ){ s.get(); sign *= -1; } return sign *
numeral(); }
int start(){ int result = prefix();
while( '-' == s.get() )result -= prefix(); return result; }};

int main()
{ using p = ::parser< ::std::stringstream >;
auto test = []( char const * s ){ ::std::cout << p{ s }.start() <<
'\n'; };
test( "4-2" ); test( "-4-2" ); test( "4--2" ); test( "-4--2" );
test( "-4---2" ); test( "--4--2" ); test( "4-2-1" ); test( "4-2--1" ); }

Marcel Mueller

unread,
Sep 5, 2015, 3:11:04 AM9/5/15
to
On 05.09.15 08.19, Gerhard Wolf wrote:
> I tried to compile this code with bcc64. it drops an error:
>
> Implicit instantiation of undefined template
> 'std::basic_stringstream<char, std::char_traits<char>,
> std::allocator<char> >'

Works for me. (gcc 4.8.2 @ eCS)
Maybe a compiler bug.

> i changed the line
> scanner s
> to
> scanner * s
> which solved this problem.

This, of course, no longer works since ::std::stringstream* cannot be
initialized from const char*.

> If the prior line compiles with a other compiler is ist a compiler
> feature/setting?

Some compilers need an option to enable C++11. But basic_stringstream
should work anyway. It is quite old.

> This change produces 'member-reference basetype 'T *' is no struct or
> union' errors on all 's' calls.
>
> how can i change this?

Undo the change. It is completely wrong.


Marcel

Paavo Helde

unread,
Sep 5, 2015, 3:43:34 AM9/5/15
to
Gerhard Wolf <lea...@gmx.de> wrote in
news:d4vfra...@mid.individual.net:

> Hi,
> i am not so experienced in template programing as I would like to be,
> so i have some questions to Stefans templat example in the "A
> Preferred or better Way?" Re-Post.
>
> I tried to compile this code with bcc64. it drops an error:
>
> Implicit instantiation of undefined template
> 'std::basic_stringstream<char, std::char_traits<char>,
> std::allocator<char> >'

This error message says that the compiler thinks stringstream is only
declared, not defined, but the standard header <sstream> where it is
defined is clearly included. Looks like a problem with the compiler or
its standard library. It might be it gets confused by the newer C++11
features like auto and lambda used in the example. You may try to rewrite
the example to use an ordinary function instead of a lambda.
0 new messages